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

我得到:

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

我使用的命令:

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


当前回答

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

它就消失了。

其他回答

确保你已经在path变量中添加了/path/to/sdk/platform-tools。

当你运行react-native run-android时,它会运行adb reverse tcp:< device-port > tcp:< local-port >命令将请求从你的设备转发到你计算机上本地运行的服务器。 如果没有找到adb,您将看到类似这样的内容。

/bin/sh: 1: adb: not found
Starting the app (.../platform-tools/adb shell am start -n 
com.first_app/com.first_app.MainActivity...
Starting: Intent { cmp=com.first_app/.MainActivity }

提出一个显而易见的建议,对我很有用。删除应用程序,重新启动服务器,重新从工具部署到设备。

在命令之前使用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之间的区别?

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

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