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

我得到:

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

我使用的命令:

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


当前回答

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

其他回答

如果在运行react-native run-android命令时,跟踪的第二行是

JS server not recognized, continuing with build...

这意味着应用程序的打包器无法启动,如果没有一些额外的步骤,应用程序将无法加载。注意,跟踪的结尾仍然报告成功:

BUILD SUCCESSFUL

问题可能是端口冲突(在我的情况下,我完全忘记了默认的IIS站点)。该问题的另一种表现形式是无法在Chrome中打开http://localhost:8081/debugger-ui URL。

一旦端口冲突得到解决,跟踪就会报告

Starting JS server...

然后一个额外的Node窗口会打开(Node…cli.js start),应用程序将成功加载/重新加载。

之后,你应该能够打开调试控制台在Chrome与http://localhost:8081/debugger-ui。

操作系统:Windows

在尝试以上两种方法后,另一种方法可以解决这个问题 (因为我安装的SDK不在默认位置,如C:\users\"user_name"\appdata\local\ SDK)

如果您注意到命令行显示:“‘adb’未被识别为内部或外部命令……”

这就是我克服的方法: 示例:我在D:\Android\ SDK中安装了SDK 所以我将在系统变量中插入path 2行:

D:\Android\sdk\tools  
D:\Android\sdk\platform-tools  

(如果你不知道如何编辑路径系统变量,这里是主题:https://android.stackexchange.com/questions/38321/what-do-i-type-in-path-variable-for-adb-server-to-start-from-cmd/38324)

然后再次运行cmd: react-native run-android

这对我很管用。

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-现在工作正常。

希望这对你有所帮助。

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

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

npm开始

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

react-native运行android

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

如果您在“开发设置”中输入了“调试服务器主机和设备端口”,请确保您删除了所输入的内容。