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

我得到:

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

我使用的命令:

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


当前回答

首先检查你的assets文件夹是否存在于这个位置\android\app\src\main\assets

如果没有,请在终端执行该命令

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

然后在android设备上使用

react-native run-android

其他回答

在Windows上

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

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

我面临着这个问题,很多搜索,我解决了这个问题。

c:\ProjectFolder\ProjectName> 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:

c: \ ProjectFolder \ ProjectName > react-native运行android

对于所有从创建-反应-原生应用程序开发出来的人,在开发过程中遇到这个问题, 这对我来说很管用 这是公认答案中的一个小细节

(在项目目录)mkdir android/app/src/main/assets

下面是需要改变的部分,因为你是在开发中,去掉——dev: false部分:

React-native bundle——platform android——entry-file index.js——bundle-output android / app / src / main /资产/ index.android。包——assets-dest android / app / src / main / res

在关闭所有终端后,从android/app/删除构建文件夹,以确保你开始干净地构建你的应用程序,打开一个新的终端,然后

(在项目目录)NPM运行android

是否会提示打包器控制台(在另一个终端)并成功构建

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

它就消失了。