React-Native run-android on specific device

React NativeAdb

React Native Problem Overview


Is it possible to use the run-android command for one specific device only?

For example, if I have three devices (or emulators) connected and I want to use run-android on only one of them?

Maybe something like adb install -s DEVICE_NUMBER?

Thanks in advance

React Native Solutions


Solution 1 - React Native

To run react-native application on optional device you can specify some flags in run command. To see available add --help:

> react-native run-android --help

Then you can specify your device id throught --deviceId

> react-native run-android --deviceId=DEVICE_ID

To see available devices ids'

> adb devices

Solution 2 - React Native

To list AVDs:

$ANDROID_HOME/tools/emulator -list-avds

To run a specific emulator:

$ANDROID_HOME/tools/emulator -avd Pixel_API_28_AOSP

To run React Native in the currently-open emulator:

react-native run-android

To choose between multiple running emulators:

adb devices
react-native run-android --deviceId=DEVICE_ID

(Last point from this answer)

Solution 3 - React Native

Elaborating on @alexander 's answer, you can use the following workflow:

cd android
./gradlew assembleDebug # assembleRelease for release builds
adb install -s <yourdevice> app/build/outputs/apk/yourapk.apk # You can check the identifier for your device with adb devices
adb reverse tcp:8081 tcp:8081 Will forward the phone's 8081 port to the computer's 8081, where the packager listens. If you are deploying over Wi-Fi, have a look at: https://facebook.github.io/react-native/docs/running-on-device-android.html#configure-your-app-to-connect-to-the-local-dev-server-via-wi-fi

In a different screen, run:

npm start # Will run the packager

If you really need this, you might want to wrap the first snippet into a script that you can parametrize with your phone's identifier.

Solution 4 - React Native

npx react-native run-android --deviceId='myDeviceId'

This works for me. don't forget '' this one. it accepts string

Solution 5 - React Native

May be we can not select which android device attached to run.

Read from official react native website:

You must have only one device connected at a time.

Solution 6 - React Native

You don't need to use run-android command to start it on specific device

Firstly, you have to start the packager:

./packager/packager.sh

Then just build an APK file and run it on target device. APK will connect to the build server, and fetch bundle from it automatically.

But if it didn't happen by some reasons, click on reload button :-)

Solution 7 - React Native

When 2 or more devices are connected

There seem to be no way to install app on a specific device in this scenario. So follow this

  1. Disconnect all devices except one
  2. run the command, in my case its react-native run-android
  3. Now connect another device
  4. repeat 2nd point
  5. when done with every device, connect all and see device ids adb devices
  6. now map device's port 8081 to computer's 8081

Eg:

 adb -s DEV_1_ID reverse tcp:8081 tcp:8081
 adb -s DEV_2_ID reverse tcp:8081 tcp:8081
 adb -s DEV_3_ID reverse tcp:8081 tcp:8081
 ...

Solution 8 - React Native

To run the app on one specific connected android device:

  1. Disconnect/Unplug all connected android devices.
  2. Connect/Plug the device you want to install the app in
  3. Run adb devices on your terminal to see the list connected devices (you should only see 1 such device as rest were disconnected)
  4. Run npx react-native run-android

This will install the React-native app on the connected device via usb.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVic ToriousView Question on Stackoverflow
Solution 1 - React NativeNerius JokView Answer on Stackoverflow
Solution 2 - React NativeFreewalkerView Answer on Stackoverflow
Solution 3 - React NativemartinarroyoView Answer on Stackoverflow
Solution 4 - React NativearslanView Answer on Stackoverflow
Solution 5 - React NativeShiView Answer on Stackoverflow
Solution 6 - React NativeAleksandrView Answer on Stackoverflow
Solution 7 - React NativeillusionistView Answer on Stackoverflow
Solution 8 - React NativeAwshaf IshtiaqueView Answer on Stackoverflow