Android 加载 JS 包失败 [英] Android failed to load JS bundle
问题描述
我正在尝试在我的 Nexus5 (android 5.1.1) 上运行 AwesomeProject.
I'm trying to run AwesomeProject on my Nexus5 (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
无法下载 JS 包.您是否忘记启动开发服务器或连接您的设备?
Unable to download JS bundle. Did you forget to start the development server or connect your device?
在 React Native iOS 中,我可以选择离线加载 jsbundle.我如何为 Android 做同样的事情?(或者至少,我可以在哪里配置服务器地址?)
In react native iOS, I can choose to load jsbundle offline. How can I do the same thing for Android? (Or at least, where can I configure the server address?)
react-native start >/dev/null 2>&1 &
adb 反向 tcp:8081 tcp:8081
请查看 dsissitka 的回答以了解更多详情.
please take a look at dsissitka's answer for more details.
- 在
android/app/src/main
下创建一个assets文件夹 curl "http://localhost:8081/index.android.bundle?platform=android";-o "android/app/src/main/assets/index.android.bundle"
- 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"
请查看 kzzzf 的回答以了解更多详情.
please take a look at kzzzf's answer for more details.
推荐答案
在服务器运行的同时将 JS 文件捆绑到您的 apk (react-native start
) 将捆绑包下载到您的应用程序的 assets 目录中:
To bundle JS file into your apk while having your server running (react-native start
) download bundle into assets directory of your app:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
在下一个版本 (0.12) 中,我们将修复 react-native bundle
命令以按预期使用 android 项目.
With the next release (0.12) we'll fix react-native bundle
command to work with android projects as expected.
这篇关于Android 加载 JS 包失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!