我试图在我的设备上第一次运行我的第一个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
当前回答
我花了半天时间来解决这个问题。
如果你使用的是28.0.0以上的API目标版本,那么你可能会遇到这个问题。
只要加上这一行
android:usesCleartextTraffic="true"
在你的Manifest Application块中。
清单应用程序块代码。
<application
....
android:usesCleartextTraffic="true"
.../>
其他回答
在我的例子中,我已经从MainApplication.java中删除了以下一行。(这是我之前错误添加的):-
进口com.facebook.react.BuildConfig;
之后,清洁项目和点击命令
react-native运行android
我在学习React Native教程时也遇到过同样的问题(在Linux上开发,目标是Android)。
这个问题帮助我通过以下步骤解决了问题。
(在项目目录)mkdir android/app/src/main/assets 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
您可以通过将上述步骤放在包的脚本部分来自动化它们。Json是这样的:
"android-linux": "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 run-android"
然后你可以每次都从你的命令行执行npm run android-linux。
如果您正在物理设备上运行应用程序并得到此错误
unable to load script from assets index.android.bundle
试着运行命令:
adb reverse tcp:8081 tcp:8081
这对我很管用……
我面临着这个问题,很多搜索,我解决了这个问题。
c:\ProjectFolder\ProjectName> 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:
c: \ ProjectFolder \ ProjectName > react-native运行android
我的mac上的McAfee阻塞端口8081,不得不将其更改为8082。
首先运行你的包服务器:
react-native start --port 8082
打开另一个终端,像往常一样启动android应用程序:
react-native run-android
一旦它完成,现在重写adb隧道的tcp端口:
adb reverse tcp:8081 tcp:8082
查看adb tcp隧道列表:
adb reverse --list
你现在应该会看到一条温馨的信息:
(reverse) tcp:8081 tcp:8082
回到你的应用程序,重新加载,完成!
PS:不要在应用程序开发设置中更改任何内容,如果你添加了“localhost:8082”,只需删除它,让它为空。
编辑: 对于所有的McAfee受害者,如果你有根访问权限,有一个更简单的解决方案,只是暂时关闭位于端口8081的McAfee进程,根本不需要更改端口:
sudo launchctl remove com.mcafee.agent.macmn