我试图在我的设备上第一次运行我的第一个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
当前回答
我的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
其他回答
对于所有从创建-反应-原生应用程序开发出来的人,在开发过程中遇到这个问题, 这对我来说很管用 这是公认答案中的一个小细节
(在项目目录)mkdir android/app/src/main/assets
下面是需要改变的部分,因为你是在开发中,去掉——dev: false部分:
React-native bundle——platform android——entry-file index.js——bundle-output android / app / src / main /资产/ index.android。包——assets-dest android / app / src / main / res
在关闭所有终端后,从android/app/删除构建文件夹,以确保你开始干净地构建你的应用程序,打开一个新的终端,然后
(在项目目录)NPM运行android
是否会提示打包器控制台(在另一个终端)并成功构建
如果您正在物理设备上运行应用程序并得到此错误
unable to load script from assets index.android.bundle
试着运行命令:
adb reverse tcp:8081 tcp:8081
这对我很管用……
对于这个问题,我只需要运行:
react-native start
then
adb reverse tcp:8081 tcp:8081
在命令行上。然后我可以运行:
react-native run-android
所以我不会浪费时间去跑:
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版本0.61.5,并试图在设备上安装调试APK)没有一个答案帮助我,我的解决方案是添加bundleInDebug: true到android/app/build。这样Gradle:
project.ext.react = [
entryFile: "index.js",
enableHermes: true, // clean and rebuild if changing
bundleInDebug: true
]
对于这个错误:"无法从资产'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