我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。
我得到:
无法从assets index.android.bundle中加载脚本
我使用的命令:
CD(项目目录) react-native开始 react-native运行android
我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。
我得到:
无法从assets index.android.bundle中加载脚本
我使用的命令:
CD(项目目录) react-native开始 react-native运行android
当前回答
您可以根据官方页面的提示进行修复。这个问题发生在真实设备上,因为JS包位于您的开发系统上,而真实设备中的应用程序不知道它的位置。
其他回答
使用npm 4.3.0版本的react-native-cli
在项目目录中,
mkdir android / app / src / main /资产 React-native bundle——platform android——dev false——entry-file index.js——bundle-output android/app/src/main/assets/index.android。Bundle——assets-dest android/app/src/main/res react-native运行android
文件名由index.android.js更改为index.js
如果您正在物理设备上运行应用程序并得到此错误
unable to load script from assets index.android.bundle
试着运行命令:
adb reverse tcp:8081 tcp:8081
这对我很管用……
同样的问题我已经有好几个月了。我最初使用@Jerry的解决方案,但这是一个错误的解决方案,因为它没有完全解决问题。相反,它所做的是将每个构建都作为产品构建,这意味着你在应用程序中所做的任何微小更改都意味着必须重新构建整个应用程序。
虽然这是一个暂时的解决方案,但从长期来看,它的效果非常糟糕,因为你不再能够利用React Native的惊人的开发工具,如热重载等。
正确的解决方法如下:
在MainApplication.java文件中,替换如下内容:
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
与
@Override
public boolean getUseDeveloperSupport() {
return true;
}
由于某些原因,BuildConfig。DEBUG总是返回false,并在assets目录中生成一个bundle文件。
通过手动将此设置为true,您将强制应用程序使用packager。这将在生产中不起作用,所以一定要将其更改为false或默认值。
别忘了也要跑
$ adb reverse tcp:8081 tcp:8081
1进入你的项目目录,检查这个文件夹是否存在android/app/src/main/assets
如果它存在,那么删除两个文件即index.android.bundle和index.android.bundle.meta 如果文件夹资产不存在,则在那里创建资产目录。
2.从您的根项目目录做
cd android && ./gradlew clean
3.最后,导航回根目录,检查是否有一个名为ledindex.js的条目文件
If there is only one file i.e. index.js then run following command react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res If there are two files i.e index.android.js and index.ios.js then run this react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res Now run react-native run-android
我在真正的android设备上也遇到过同样的问题。
解决方案:基于Niltoid的回答
查找本地IP 打开应用程序,摇晃你的安卓设备 去开发设置和>调试服务器… 粘贴你的IP和端口;X.X.X.X:8088"(其中X是您的本地IP)
Mac用户:打开你的网络首选项,在这里你会得到你的本地IP。