我试图在我的设备上第一次运行我的第一个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
当前回答
如果您正在物理设备上运行应用程序并得到此错误
unable to load script from assets index.android.bundle
试着运行命令:
adb reverse tcp:8081 tcp:8081
这对我很管用……
其他回答
如果您正在物理设备上运行应用程序并得到此错误
unable to load script from assets index.android.bundle
试着运行命令:
adb reverse tcp:8081 tcp:8081
这对我很管用……
使用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
对于这个错误:"无法从资产'index.android.bundle'中加载脚本"
1).检查“assets”文件夹:mkdir android\app\src\main\assets
如果文件夹不可用,请手动创建名称为assets的文件夹。并在终端执行Curl命令。
2). Curl命令:Curl "http://localhost:8081/index.android.bundle?android平台=“- o”安卓/ app / src / main /资产/ index.android.bundle”
它将创建“index.android”。Bundle "文件在资产文件夹自动解决了这个问题。
3). react-native run-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