JustWonder
JustWonder

Reputation: 2443

React native Android Example does not work

I cloned the repository: https://github.com/facebook/react-native and try to run the UIExplorer example on Android emulator.

./gradlew :Examples:UIExplorer:android:app:installDebug
./packager/packager.sh

I got this error message on the Android emulator:

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

I understand this is somewhat similar to this one: react native android failed to load JS bundle

But here I had to use the command "./packager/packager.sh" to run the example. So the answer above does not apply to this case.

Upvotes: 3

Views: 2590

Answers (2)

lu_ko
lu_ko

Reputation: 4285

It looks like your packager is not accessible from application. You should start React Native Packager at first. It could be done various ways - it depends on your OS and project, examples:

./packager/packager.sh
packager\packager.bat
npm start
react-native start
node "local-cli\cli.js" start
node node_modules/react-native/local-cli/cli.js start

Also check packager configuration in your project (hostname and port at least).

Upvotes: 1

Andrei Ovidiu Coman
Andrei Ovidiu Coman

Reputation: 201

In order for the app to be able to download the JS Bundle, the packager has to create and serve the JS bundle, and the emulator has to be able to connect to it.

To verify that the bundle is created and served correctly, try browsing to this page in your web browser. This should connect to the packager and get the bundle as the answer. If the packager received the request, the following request message should appear in the packager console:

<START> request:/Examples/UIExplorer/UIExplorerApp.android.bundle?platform=android

If the packager created the correct bundle, it would return get a huge file that starts with something like "__DEV__ = true;. If these two steps did not work, then there's an issue with the packager and you can report the issue on github.

To verify that the emulator can connect to your packager, when you tap Reload JS you should see the same request message in the packager console as above. If no such message appears, then the emulator can't connect to your machine.

Upvotes: 5

Related Questions