我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。
我得到:
无法从assets index.android.bundle中加载脚本
我使用的命令:
CD(项目目录) react-native开始 react-native运行android
我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。
我得到:
无法从assets index.android.bundle中加载脚本
我使用的命令:
CD(项目目录) react-native开始 react-native运行android
当前回答
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。
其他回答
我在真正的android设备上也遇到过同样的问题。
解决方案:基于Niltoid的回答
查找本地IP 打开应用程序,摇晃你的安卓设备 去开发设置和>调试服务器… 粘贴你的IP和端口;X.X.X.X:8088"(其中X是您的本地IP)
Mac用户:打开你的网络首选项,在这里你会得到你的本地IP。
提出一个显而易见的建议,对我很有用。删除应用程序,重新启动服务器,重新从工具部署到设备。
就我而言,我忘了Android模拟器的wifi是禁用的。 为了解决这个问题,我只是向下滑动通知栏来展开菜单并启用Wifi连接。
激活Wifi连接后,我的问题就解决了。
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。
如果已经尝试了以上所有解决方案,但仍然遇到错误。 试着和我一样配置你的genymotion: