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

我得到:

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

我使用的命令:

CD(项目目录) react-native开始 react-native运行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-现在工作正常。

希望这对你有所帮助。

其他回答

当我更新react-native到0.49.5时,这个问题出现了,当我遵循这个破坏性的变化和弃用

它就消失了。

我也面临着这个问题,因为当我在模拟器上运行项目时,它的工作很好,但在真实的设备上,它给出了这个错误。所以我用下面的方法来解决这个问题

第一步:首先打开cmd,进入SDK管理器Platform-tools文件夹

cd C:Development\Android\Sdk\Platform-tools

第二步:现在运行这个命令:

adb devices

执行此命令后,检查命令提示符中列出的设备

第三步:现在运行这个

adb reverse tcp:8081 tcp:8081

现在您的设置完成了

第四步:进入您的项目目录并运行此命令

react-native run-android

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

我认为在所有其他解决方案之前,首先要做的是:

1. 检查您的设备是否在线?

2. 如果您在真实设备上运行应用程序,那么该设备应该与运行开发服务器的网络相同。

更多信息请访问本页。

我不是在真正的设备上遇到这个问题,而是在模拟器上遇到的。在尝试使用android studio运行代码之前,我通过在终端中运行react-native start来修复它。在终端中运行react-native run-android时,我从未遇到过这个问题。