Antoine Auffray
Antoine Auffray

Reputation: 1293

React Native run on multiple simultaneous Android emulators

I would like to test my app on at least 2 Android emulators simultaneously. I can start 2 emulators but can't seem to find how to react-native run-android my app on 2 emulators with ADB. If possible I would also like to be able to run a react-native log-android on each one while testing my app.

Is there a way to do so ?

Upvotes: 16

Views: 16531

Answers (6)

Dzan Hadzifejzovic
Dzan Hadzifejzovic

Reputation: 1

You can open another(second) terminal,while in first is open first device(for example Pixel 8) on port 8081 (default port). In second terminal run command npx expo start and terminal will suggest you another port(8082 probably) with question: 'Use port 8082 instead? » (Y/n)',enter Y and then u can type Shift + A,and select another emulator.

Upvotes: 0

Rusty
Rusty

Reputation: 4473

First you check available android devices by running the following command.

adb devices

enter image description here

After that you can use the following command to start react native project with specific port and device id.

npm run android -port PORT_NO -deviceId=DEVICE_ID

In the example above we can run the command in two separate terminals.

npm run android -port 9988 -deviceId=067682514L113728 
npm run android -port 9989 -deviceId=emulator-5554

Upvotes: 0

Burhan Yılmaz
Burhan Yılmaz

Reputation: 804

You can only do it on different ports. Because one port, one listener :/
Solve:

react-native start --port 9988
./emulator -port 9988 -avd devicename1

react-native start --port 9999
./emulator -port 9999 -avd devicename2

Edit2:

Before running the emulator, You can write in the terminal and then run it:

function emulator { cd "$(dirname "$(which emulator)")" && ./emulator "$@"; }

First emulator is react .

emulator -port 9988 @react
react-native run-android ( automaticaly detect emulator )

Second emulator is r .

emulator -port 8081 @r
react-native run-android (automaticaly detect emulator )

enter image description here

Upvotes: 13

Simon
Simon

Reputation: 6462

Using Genymotion, you just have to start 2 instances and start them as if there was only one (react-native run-android to install the app and react-native start)

Upvotes: -1

Anusha
Anusha

Reputation: 229

In order to run your react application on multiple emulators, just start 2 emulators as usual and then use the command react-native run-android.

You can even specify any port number as react-native run-android --port 8084 if you want. Your app will start on both the emulators simultaneously. :)

Have a look here

Upvotes: 13

Bilal Abdeen
Bilal Abdeen

Reputation: 1947

The accepted answer by @Burhan Yılmaz did NOT work for me. This is probably due to new updates and development in the relevant software. The following steps demonstrate what worked for me.

  1. Start the 1st emulator, e.g. emulator -avd Nexus_S_API_28

  2. Start the 2nd emulator, e.g. emulator -avd Nexus_S_API_28_2

  3. Start React-Native in the same way, which you would usually use (without specifying any ports.) react-native run-android

This sends a copy of the code to both devices. However, each device runs its copy in isolation from the other device.

Environment Details:

  • MS Windows 10
  • Android SDK 29.0.2
  • React-Native: 0.61.2

Upvotes: 10

Related Questions