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

我得到:

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

我使用的命令:

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


当前回答

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

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

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

更多信息请访问本页。

其他回答

如果您使用的是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

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

实际上,在我的情况下(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
]

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

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