我试图在我的设备上第一次运行我的第一个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。
其他回答
对于这个问题,我只需要运行:
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
每一次。
我花了半天时间来解决这个问题。
如果你使用的是28.0.0以上的API目标版本,那么你可能会遇到这个问题。
只要加上这一行
android:usesCleartextTraffic="true"
在你的Manifest Application块中。
清单应用程序块代码。
<application
....
android:usesCleartextTraffic="true"
.../>
如果已经尝试了以上所有解决方案,但仍然遇到错误。 试着和我一样配置你的genymotion:
我在学习React Native教程时也遇到过同样的问题(在Linux上开发,目标是Android)。
这个问题帮助我通过以下步骤解决了问题。
(在项目目录)mkdir android/app/src/main/assets 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
您可以通过将上述步骤放在包的脚本部分来自动化它们。Json是这样的:
"android-linux": "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 run-android"
然后你可以每次都从你的命令行执行npm run android-linux。
对于这个错误:"无法从资产'index.android.bundle'中加载脚本"
1).检查“assets”文件夹:mkdir android\app\src\main\assets
如果文件夹不可用,请手动创建名称为assets的文件夹。并在终端执行Curl命令。
2). Curl命令:Curl "http://localhost:8081/index.android.bundle?android平台=“- o”安卓/ app / src / main /资产/ index.android.bundle”
它将创建“index.android”。Bundle "文件在资产文件夹自动解决了这个问题。
3). react-native run-android