My React-Native(0.68.1) project runs properly on my emulator when using npx react-native run-android command and everything works fine with the metro bundler instance created by this command.
Only when I run project from android studio (2021.3.1 Patch 1) , app is build successfully and installed on emulator, but cannot connect to metro bundler (which I separately run using npx react-native start command).
I wanted to try and update the debug server & port as mentioned in other similar questions , but I cannot access the debug app menu even after dismissing the error (menu doesn't show when ipress the shortcut)
Issue also occurs on build installed on emulator via npx react-native run-android when I close the app and metro bundler created by the command and start a separate metro bundler. In this case but I am able to enter settings menu and enter "debug server and port " to 10.0.2.2:8081 and app connects to metro.
I am using mac mini m1.
To fix this issue
first of all, start your emulator and run adb reverse tcp:8081 tcp:8081 this command on the terminal and then run npx react-native start and then run your project in the android studio and it will automatically link your app to that bundle
This is a strange error when I ran React Native (0.63.2) app on Android 8.1 emulator with
npx react-native run-android
Here is the full warning message:
warn No apps connected. Sending "devMenu" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.
info Opening developer menu...
Tried adb reverse tcp:8081 tcp:8081 but didn't help. The emulator was working fine. What can go wrong here?
Note: Answer targets only those visitors, who are facing this issue after successfully running once on device
npx react-native run-android
//once its installed on device next time just do
npx react-native start
installs app at your device on first run. I was facing same issue only when I tried npx react-native run-android second time.
So I used npx react-native start then
I just opened my latest app installed by last run and its working and showing me the updates as well
When I try to start my react-native init project with this command npx react-native start nothing happens in the emulator.
enter image description here
Command npx react-native start is for starting up the bundler (Metro)
to run it on an android emulator or device you need npx react-native run-android.
Before that please make sure you have either a real device connected or an emulator ready.
You can follow or check by using this guide for your Android environment setup.
I'm doing a react-native app.
When I launch my app with react-native start or npm run start and react-native run-android, it install on my phone the app but don't launch it automatically and when I launch it by myself, I have this error :
Can you help me I don't know what is my problem ?
thank
I think your phone and your computer are not connected to the same network
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?
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
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)
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.
npx react-native run-android --deviceId='myDeviceId'
This works for me. don't forget '' this one. it accepts string
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.
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 :-)
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.
To run the app on one specific connected android device:
Disconnect/Unplug all connected android devices.
Connect/Plug the device you want to install the app in
Run adb devices on your terminal to see the list connected devices (you should only see 1 such device as rest were disconnected)
Run npx react-native run-android
This will install the React-native app on the connected device via usb.
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.
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
Disconnect all devices except one
run the command, in my case its react-native run-android
Now connect another device
repeat 2nd point
when done with every device, connect all and see device ids adb devices
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
...