我试图在我的设备上第一次运行我的第一个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
当前回答
对我来说,gradle清洁修复了它,当我在Android上有问题
cd android
./gradlew clean
其他回答
在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**
]
当我更新react-native到0.49.5时,这个问题出现了,当我遵循这个破坏性的变化和弃用
它就消失了。
我刚刚遇到了完全相同的问题,并解决了它。希望对大家有所帮助。
假设您正在组装一个发布应用程序包(.apk)
Check if your assets folder exist?: \android\app\src\main\assets If not, create one. After executing "Assemble Release", check if there is anything in that folder(\android\app\src\main\assets) If not, find js bundle file(index.android.bundle), which should be in more than one of the following paths: *a)\android\app\build\intermediates\merged_assets\release\out\index.android.bundle b)\android\app\build\intermediates\merged_assets\release\mergeReleaseAssets\out\index.android.bundle c)\android\app\build\intermediates\assets\release\index.android.bundle d)\android\app\build\generated\assets\react\release\index.android.bundle*
更好的方法是使用“Everything”来搜索文件名:index.android.bundle。
然后将这个文件复制到你的assets文件夹(\android\app\src\main\assets\index.android.bundle) 回到powershell或命令控制台,执行:
React-native run-android——variant=release
它应该会起作用。
好运!
我在学习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。
我的mac上的McAfee阻塞端口8081,不得不将其更改为8082。
首先运行你的包服务器:
react-native start --port 8082
打开另一个终端,像往常一样启动android应用程序:
react-native run-android
一旦它完成,现在重写adb隧道的tcp端口:
adb reverse tcp:8081 tcp:8082
查看adb tcp隧道列表:
adb reverse --list
你现在应该会看到一条温馨的信息:
(reverse) tcp:8081 tcp:8082
回到你的应用程序,重新加载,完成!
PS:不要在应用程序开发设置中更改任何内容,如果你添加了“localhost:8082”,只需删除它,让它为空。
编辑: 对于所有的McAfee受害者,如果你有根访问权限,有一个更简单的解决方案,只是暂时关闭位于端口8081的McAfee进程,根本不需要更改端口:
sudo launchctl remove com.mcafee.agent.macmn