Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup 2 android emulators in android studio to test react native app

I added one more android emulator for react native 0.59 app test. I am able to launch 2 emulators. The adb devices command has the following output:

List of devices attached
emulator-5554   device
emulator-5556   device

When there is one emulator, I use on cmd terminal to do react-native run-android and another one to do react-native log-android. The backend server is running on the same PC. Here is the virtual devices in android studio:

enter image description here

What I would like to do is to launch 2 app representing 2 users connecting to the backend at the same time for testing. I tried to launched one app when 2 emulators are running and the loading of the app is extremely slow. It seems that the 2 app need to be launched on 2 different ports and the solutions I found online seems not working here. Also react-native log-android throws error when encountering 2 emulators.

like image 953
user938363 Avatar asked May 20 '19 06:05

user938363


People also ask

How can I run two emulators at the same time in Android Studio?

You can run multiple emulators at the same time simply by running your app again. When the AVD manager pops up, instead of selecting your already running emulator, click 'Launch Emulator' and select another emulator to launch. Thank you for the answer!

Can you run multiple Android emulators?

You can run multiple android device emulators (Create Multiple Device Definitions. Check.) You can run more than one emulator. (You can launch more than one at a time by multi-selecting in the Run option.


Video Answer


2 Answers

Try running the metro-bundler at 2 different ports. Open up one terminal in you project root and use the default command as below,

react-native start

This starts one server at port 8081 default.

And in another terminal run

react-native start --port=9090

This starts another server at port 9090

Now in a third terminal run

react-native run-android

This will compile and start the apps in both your running emulators at default port.

When the apps start up properly, select one emulator and open up the dev menu using Ctrl+M.

Click Dev Settings button at the bottom.

Click Debug server host & port for device button.

Type localhost:9090 or ip_address:9090 and click OK button

Reload the app and it will fetch the js bundle from your react-native server running at 9090 port

like image 175
Nishant Nair Avatar answered Oct 17 '22 13:10

Nishant Nair


log-android from react-native CLI is simply using adb logcat to show the Android logs.

adb has a -s parameter that lets you specify the emulator serial. First you'll need to list the currently open devices using adb devices. You'll get a list, for example:

List of devices attached
emulator-5554   device

Now you can specify the specific device:

adb -s emulator-5554 logcat *:S ReactNative:V ReactNativeJS:V

You can run it multiple times for all of the running devices that you wish to see logs for.

like image 21
Artal Avatar answered Oct 17 '22 14:10

Artal