React原生Android示例不起作用 [英] React native Android Example does not work
问题描述
我克隆了存储库:https://github.com/facebook/react-native 并尝试在 Android 模拟器上运行 UIExplorer 示例.
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
我在 Android 模拟器上收到此错误消息:
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?
我知道这有点类似于这个:react native android 加载 JS 包失败
I understand this is somewhat similar to this one: react native android failed to load JS bundle
但在这里我不得不使用命令./packager/packager.sh"来运行示例.所以上面的答案不适用于这种情况.
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.
推荐答案
为了让应用能够下载 JS Bundle,打包者必须创建并提供 JS Bundle,而模拟器必须能够连接到它.
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
如果打包器创建了正确的包,它会返回一个以 "__DEV__ = true;
开头的大文件.如果这两个步骤不起作用,则说明存在问题打包程序,您可以在 github 上报告问题.
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.
要验证模拟器是否可以连接到您的打包程序,当您点击 Reload JS
时,您应该会在打包程序控制台中看到与上述相同的请求消息.如果没有出现此类消息,则模拟器无法连接到您的机器.
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.
这篇关于React原生Android示例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!