Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Mar 27, 2024
Difficulty: Easy

Running React Native Apps on Android

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

Introduction

This article will show you how to run a react native app on an android device or emulator. If you already have the required driver's updated emulator installed, the process is actually quite simple. If you don't, don't worry; we'll walk you through the process of setting up your environment to execute react native-run on android devices.

With React Native, cross-platform mobile apps can be developed that look and feel native on both iOS and Android. If you use React Native, you can test your app on an emulator or on an actual device.

To run React Native on Android, you will need the following prerequisites:

How to Run React Native App On Physical Android Device

When you've finished developing your React Native app, it's a good idea to test it on an actual android phone. The reason for this is that emulators behave differently from real devices.

It is essential that you enable Usb debugging on your Android device before you can run a debug app. This can be done by following these steps:

 Go to About Phone in Settings

 

You will need to click the Build number or MIUI version multiple times until you are notified that you are a developer.

 

 

  In Settings or Additional Settings, you will find a Developer Option.

 

 

 

 After that, enable USB debugging and Developer Option.

 

Run the following command on the terminal after connecting your Android phone to the computer with a USB cable.

adb devices
npx react-native run-android  or react-native run-android

You may encounter an error that reads "bridge configuration is not available.". If so, use the following command. The device name should be replaced with yours that you got the name using adb devices. when you type <device name> here.

adb -s <device name> tcp:8081 tcp:8081
react-native run-android

The react native app will run successfully on Android phones if you have followed all the steps listed above correctly. However, it may take some time, depending on the environment.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Run React Native on Android Emulator

Developers can develop Android apps using the official IDE, Android Studio. You can download it for free from the official website. Android Studio is available for Mac, Windows, and Linux.

After installing it, you can start an emulator of your choice by going to Tools -> AVD Manager in Android Studio.  

You can also make your own emulators with your own requirements for hardware. You can proceed to the next step once you've got an emulator running. 

There is no need to do anything more than run the two commands:

cd ~/path/to/template
npm install && react-native run-android

It would help if you didn't use Windows' command prompt because it is weird. It is also possible to use Visual Studio Code, which has a Terminal that's directly connected to the correct folder. It has a built-in Terminal that behaves just like the one on MacOS. Select View -> Terminal to enable the Terminal:

Frequently Asked Questions

What to do if no android device is available?

You can use the emulator bundled with android studio.

I need to debug my React Native app using the Android emulator. How can I do that?

You can press ctr+D for the emulator.

How to check the name of the device connected?

Use adb device to find the device name.

Conclusion

In this post, we discussed a lot of steps. Therefore, let's wrap up with a recap of what we've learned.

The first step was to set up the Android development environment. As part of this process, Android Studio was installed, the Android SDK was downloaded, and all environment variables were configured.

Last but not least, we examined how to run our app on a real Android device and on an emulator.

Most of the things we've discussed above can be useful when testing your Android app during its development phase if you're building a React Native application.

You can also consider our React Js Course to give your career an edge over others.

Topics covered
1.
Introduction
2.
How to Run React Native App On Physical Android Device
3.
Run React Native on Android Emulator
4.
Frequently Asked Questions
4.1.
What to do if no android device is available?
4.2.
I need to debug my React Native app using the Android emulator. How can I do that?
4.3.
How to check the name of the device connected?
5.
Conclusion