Android无法加载JS捆绑包 [英] Android failed to load JS bundle

查看:140
本文介绍了Android无法加载JS捆绑包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在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?)

  1. react-native start > /dev/null 2>&1 &
  2. adb reverse tcp:8081 tcp:8081
  1. react-native start > /dev/null 2>&1 &
  2. adb reverse tcp:8081 tcp:8081

请查看dsissitka的答案以获取更多详细信息.

please take a look at dsissitka's answer for more details.

  1. android/app/src/main
  2. 下创建资产文件夹
  3. curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
  1. create an assets folder under android/app/src/main
  2. 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.

推荐答案

要在服务器运行(react-native start)时将JS文件捆绑到apk中,将捆绑下载到应用程序的资产目录中:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆