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

我得到:

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

我使用的命令:

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


当前回答

在命令之前使用NPX对我来说是有效的,命令就像下面这样。

npx 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

为什么我们使用npx,这里是npx和npm之间的区别?

其他回答

在mac中也有同样的问题,在花了2天之后,我终于能够得到它的工作。

由于模拟器蜂窝数据被关闭,我得到了无法从assets index.android.bundle加载脚本,确保你的包正在运行。

确保你的模拟器蜂窝数据是打开的,通过做这个包服务器能够捆绑index.android.js。希望这对那些处于发展阶段的人有所帮助。

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

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

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

对于这个问题,我只需要运行:

react-native start

then

adb reverse tcp:8081 tcp:8081

在命令行上。然后我可以运行:

react-native run-android

所以我不会浪费时间去跑:

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

每一次。