我试图在我的设备上第一次运行我的第一个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
当前回答
首先检查你的assets文件夹是否存在于这个位置\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
然后在android设备上使用
react-native run-android
其他回答
这可能是由React Native项目代码库中未链接的资产引起的,例如,当您重命名项目应用程序/包id或添加外部包时没有正确链接。
在你的项目根目录下试试:
react-native link
react-native run-android
我通过这个CMD来解析它:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
我在学习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。
The most upVoted answer seems working but become hectic for developers to see their minor changes after couple of minutes. I solved this issue by following these steps: 1- Push my code to bitbucket/github repo ( to view the changes later ) 2- cut paste android folder to any safe location for recovery 3- delete the android folder from my project 4- run react-native upgrade 5- Now, I see all the changes between the previous and the lastest build (using VsCode) 6- I found the issue in build.gradle file in these lines of code.
ext {
buildToolsVersion = "28.0.2"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
}
7-我复制了这些行(由react-native升级脚本生成,并再次删除android文件夹。 8-然后我剪切粘贴android文件夹回到我的项目文件夹,我在第2步剪切粘贴。 9 -替换构建。Gradle文件行与复制的。 10-现在工作正常。
希望这对你有所帮助。
在Windows上
如果你确定node.js已经成功安装在你的系统上,请检查系统环境变量并在系统变量路径中添加C:\windows\system32