I am developing a react-native
application and every time I want to update the changes to either an actual phone or an emulator, I execute react-native run-android
(Sometimes I use the reload functionality in the emulator).
My question is whether there is the possibility to specify in which device/emulator the command will run, since when I have both connected it will run and update the app in the most recently run/plugged.
So I would imagine something like this:
react-native run-android --device=XXXXXX
I have been doing some research and haven't found an answer so far, so I hope someone has a clue about it. Thanks!
npx react-native run-android // or if you have a npm script, 'npm run android'
Ensure the devices are plugged in, and get their deviceIds with adb devices
, then npx react-native run-android --deviceId [DEVICE_ID]
First, plug the device in, or start the emulator with Android Emulator CLI.
emulator -list-avds
will list your avds (android virtual devices), e.g. Pixel_2_API_29
emulator -avd Pixel_2_API_29
or emulator @Pixel_2_API_29
will start a specified device.emulator -help
for more info.npx react-native run-android
. It will start your app on all android devices, both physical and AVDs.
If you wanted to specify only 1 device (why not run on all of them!):adb devices
, to get list of device IDs, e.g. 1cfe4i231414523
npx react-native run-android --deviceId 1cfe4i231414523
PS: React native getting started guide specifies that you should uninstall react-native, and instead use the package through npx. To uninstall npm rm -g react-native
. Now, everytime you want to run react-native, use npx react-native [command]
. What npx does is it looks in the local node_modules
and runs it from there, as opposed to a possibly outdated global react-native
package.
If you go through the docs then you would find that there are two more commands available to start the server and there is no such react-native run-android ---//deviceID command available until now but, you can customize react native code in node_modules to make that command for yourself.
The two commands are:
1)react-native start
2)npm start
Cheers :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With