React Native Android - Unable to download JS bundle

One of the common error while trying to run your first react native project on android is the ubiquitous error about unable to download js bundle.

That is, when you run react-native run-android, you get following error:

Unable to download JS bundle. Did you forget to start the development server or connect your device?

React Native Android - Unable to Download JS Bundle

As part of react native application development, we need to connect our device to the computer through USB or wifi and run the application by using react-native run-android. But sometimes this fails with 'unable to download js bundle' error. This error typically happens when the app running on the device is not able to connect to react native development server running on the computer.

Typically when you run react-native run-android, it automatically starts the react native development server. If not, you can start it by doing following:

# in your react native project folder
$ react-native start

Once you have ensured that react native server is running properly, you can follow below steps.

If you are using USB, you need to ensure that:

  1. Device is connected to the computer using USB
  2. USB Debugging is enabled on the device
  3. ADB reverse connection is established successfully

To establish adb reverse, use following command

$ adb reverse tcp:8081 tcp:8081

One you do this, go back to your device and click on 'Reload JS' and it should work successfully.

If you are using WiFi, you need to ensure that:

  1. Make sure your device and computer are on the same wifi
  2. Go to your device and open the in app developer menu (You can access the developer menu by shaking your device)
  3. Go to Dev Settings -> Debug server host for device
  4. Type in your computer IP address and the port of the react native dev server (e.g. 10.0.1.1:8081).

Once you do that, go back and click on 'Reload JS' and it should work now.