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

我得到:

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

我使用的命令:

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


当前回答

在MAC或Windows上,我们可以在1秒内解决这个问题

在你的项目中搜索project.ext.react这个术语

并在bundleInDebug: true中做一个更改,添加这一行。并再次运行您的项目。

    project.ext.react = [
    entryFile: "index.js",
    enableHermes: true,  // clean and rebuild if changing
    bundleInDebug: true  // **add this line only**
]

其他回答

去开发设置->调试服务器主机和端口的设备->输入您的计算机Wifi IP地址(Mac OS:去系统首选项-> Wifi获取Wifi IP地址)

最终重建应用程序并运行

在MAC或Windows上,我们可以在1秒内解决这个问题

在你的项目中搜索project.ext.react这个术语

并在bundleInDebug: true中做一个更改,添加这一行。并再次运行您的项目。

    project.ext.react = [
    entryFile: "index.js",
    enableHermes: true,  // clean and rebuild if changing
    bundleInDebug: true  // **add this line only**
]

我通过这个CMD来解析它:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

如果您正在物理设备上运行应用程序并得到此错误

unable to load script from assets index.android.bundle

试着运行命令:

adb reverse tcp:8081 tcp:8081

这对我很管用……

确保你已经在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 }