我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。

我得到:

无法从assets index.android.bundle中加载脚本

我使用的命令:

CD(项目目录) react-native开始 react-native运行android


当前回答

此问题也可能是由于设备/模拟器的蜂窝数据被关闭引起的。一定要检查一下。

其他回答

对于这个错误:"无法从资产'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

确保metro构建器正在运行,以使物理设备和服务器同步

首先,运行这个命令来运行metro builder

npm开始

然后你可以在react native中开始构建

react-native运行android

他们这次应该不会出错了。如果您希望您的代码在更改时重新加载。摇动你的设备,然后点击“启用Live Reload”

The most upVoted answer seems working but become hectic for developers to see their minor changes after couple of minutes. I solved this issue by following these steps: 1- Push my code to bitbucket/github repo ( to view the changes later ) 2- cut paste android folder to any safe location for recovery 3- delete the android folder from my project 4- run react-native upgrade 5- Now, I see all the changes between the previous and the lastest build (using VsCode) 6- I found the issue in build.gradle file in these lines of code.

ext {
buildToolsVersion = "28.0.2"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
}

7-我复制了这些行(由react-native升级脚本生成,并再次删除android文件夹。 8-然后我剪切粘贴android文件夹回到我的项目文件夹,我在第2步剪切粘贴。 9 -替换构建。Gradle文件行与复制的。 10-现在工作正常。

希望这对你有所帮助。

使用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

在Windows上

如果你确定node.js已经成功安装在你的系统上,请检查系统环境变量并在系统变量路径中添加C:\windows\system32