我试图在我的设备上第一次运行我的第一个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
当前回答
此问题也可能是由于设备/模拟器的蜂窝数据被关闭引起的。一定要检查一下。
其他回答
实际上,在我的情况下(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
]
当我更新react-native到0.49.5时,这个问题出现了,当我遵循这个破坏性的变化和弃用
它就消失了。
在mac中也有同样的问题,在花了2天之后,我终于能够得到它的工作。
由于模拟器蜂窝数据被关闭,我得到了无法从assets index.android.bundle加载脚本,确保你的包正在运行。
确保你的模拟器蜂窝数据是打开的,通过做这个包服务器能够捆绑index.android.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
如果您使用的是Windows,则按照以下方式运行命令,或者如果您得到错误“无法找到入口文件index.android.js”
mkdir android主要\ app \ src \ \资产 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