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

我得到:

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

我使用的命令:

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


当前回答

我通过这个CMD来解析它:

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

其他回答

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

最终重建应用程序并运行

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

Ubuntu

第一次,我用react-native init project-name创建了新的应用程序。 我得到了同样的错误。 所以在我的例子中,我执行以下步骤来解决这个问题。

首先执行sudo chown user-name-of-pc /dev/kvm。 从Android手机调试时,选择“使用USB传输照片(PTP)”。 在project-name/android/app/src/main中创建文件夹资产 确保index.js在你的项目根目录下可用,然后从控制台在CD项目名称目录后运行下面的命令。

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

或 对于index.android.js

React-native bundle——platform android——dev false——entry-file index.android.js——bundle-output android/app/src/main/assets/index.android. jsBundle——assets-dest android/app/src/main/res

在“android-studio/bin”目录下执行。/studio.sh命令。它将开放Android Studio。 执行命令react-native Run -android。

我也面临着这个问题,因为当我在模拟器上运行项目时,它的工作很好,但在真实的设备上,它给出了这个错误。所以我用下面的方法来解决这个问题

第一步:首先打开cmd,进入SDK管理器Platform-tools文件夹

cd C:Development\Android\Sdk\Platform-tools

第二步:现在运行这个命令:

adb devices

执行此命令后,检查命令提示符中列出的设备

第三步:现在运行这个

adb reverse tcp:8081 tcp:8081

现在您的设置完成了

第四步:进入您的项目目录并运行此命令

react-native run-android

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

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