Reputation: 1947
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
?
Upvotes: 107
Views: 193756
Reputation: 12524
There seem to be no way to install app on a specific device in this scenario. So follow this
npx react-native run-android
adb devices
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
...
Upvotes: 0
Reputation: 3227
To run react-native application on optional device you can specify some flags in run command. To see available add --help:
npx react-native run-android --help
Then you can specify your device id throught --deviceId
npx react-native run-android --deviceId=DEVICE_ID
To see available devices ids'
adb devices
Upvotes: 209
Reputation: 7315
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:
npx react-native run-android
To choose between multiple running emulators:
adb devices
npx react-native run-android --deviceId=DEVICE_ID
(Last point from this answer)
Upvotes: 57
Reputation: 5075
You can do npx react-native run-android --list-devices
. This will allow you to select a device/emulator among the available ones (connected as well as disconnected).
Upvotes: 17
Reputation: 1391
If you're using React >= 0.68.x. Just type this:
npx react-native run-android --deviceId=VCR4XCORPFTKAQFA
VCR4XCORPFTKAQFA is recovered typing adb devices in your terminal.
Upvotes: 2
Reputation: 32532
Actually, first of all, be sure about adb
installation which I think while setting up your RN environment you have it for sure, follow these steps:
Connect your Android external device to your computer with a cable
Run this command adb devices
and you will see the result at least:
List of devices attached
9999xxx3434yyy device
FYI: the 9999xxx3434yyy
is your device id
Put the given device id in the following command
npx react-native run-android --deviceId="9999xxx3434yyy"
or
yarn run react-native run-android --deviceId="9999xxx3434yyy"
HINT: If the device is a Xiaomi product keep watching the phone screen because you should grand install access.
Upvotes: 3
Reputation: 1144
npx react-native run-android --deviceId='myDeviceId'
This works for me. don't forget ''
this one. it accepts string
Upvotes: 16
Reputation: 941
To run the app on one specific connected android device:
adb devices
on your terminal to see the list connected devices (you should only see 1 such device as rest were disconnected)npx react-native run-android
This will install the React-native app on the connected device via usb.
Upvotes: 1
Reputation: 520
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.
Upvotes: 3
Reputation: 9701
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.
Upvotes: 23
Reputation: 4936
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 :-)
Upvotes: 2