I’m trying to run AwesomeProject on my Mi4 (android 5.1.1).
I’m able to build the project and install it on the device. But when I run it, I got a red screen saying
Unable to download JS bundle. Did you forget to start the development server or connect your device?
In react native iOS, I can choose to load jsbundle offline. How can I do the same thing for Android?
You might find that if you deploy your app to your Android device rather than an emulater you get a red screen of death with an error saying Unable to load JS Bundle. You need to set the debug server for your device to be your computer running react…either its name OR IP address.
- Press the device Menu button
- Select Dev Settings
- Select Debug server host for device
- Type in your machine’s IP and Reload JS plus the react port e.g. 192.168.1.10:8081
More info: http://facebook.github.io/react-native/docs/running-on-device-android.html
If you tried to run your app before but failed, delete it from your android device.
1 -> Run
$ react-native run-android
2-> Open the React Rage Shake Menu from within your app on your android device, go to Dev Settings and then to Debug server host & port for device. There enter your server IP (IP of your computer) and host 8081, e.g. 192.168.50.35:8081. On a mac you can find the IP of your computer at System Preferences -> Network -> Advanced… -> TCP/IP -> IPv4 Address.
3-> Open the Rage Shake Menu again and click Reload JS.
To run with local server, run the following commands under your react-native project root directory
cd (App Dir)
react-native start > /dev/null 2>&1 &
adb reverse tcp:8081 tcp:8081
To run without a server, bundle the jsfile into the apk by running:
create an assets folder under android/app/src/main
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"