我试图在我的设备上第一次运行我的第一个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

就我而言,我忘了Android模拟器的wifi是禁用的。 为了解决这个问题,我只是向下滑动通知栏来展开菜单并启用Wifi连接。

激活Wifi连接后,我的问题就解决了。

我刚刚遇到了完全相同的问题,并解决了它。希望对大家有所帮助。

假设您正在组装一个发布应用程序包(.apk)

Check if your assets folder exist?: \android\app\src\main\assets If not, create one. After executing "Assemble Release", check if there is anything in that folder(\android\app\src\main\assets) If not, find js bundle file(index.android.bundle), which should be in more than one of the following paths: *a)\android\app\build\intermediates\merged_assets\release\out\index.android.bundle b)\android\app\build\intermediates\merged_assets\release\mergeReleaseAssets\out\index.android.bundle c)\android\app\build\intermediates\assets\release\index.android.bundle d)\android\app\build\generated\assets\react\release\index.android.bundle*

更好的方法是使用“Everything”来搜索文件名:index.android.bundle。

然后将这个文件复制到你的assets文件夹(\android\app\src\main\assets\index.android.bundle) 回到powershell或命令控制台,执行:

React-native run-android——variant=release

它应该会起作用。

好运!

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

如果已经尝试了以上所有解决方案,但仍然遇到错误。 试着和我一样配置你的genymotion: