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

我得到:

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

我使用的命令:

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


当前回答

我刚刚遇到了完全相同的问题,并解决了它。希望对大家有所帮助。

假设您正在组装一个发布应用程序包(.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

它应该会起作用。

好运!

其他回答

我的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

在Windows上

如果你确定node.js已经成功安装在你的系统上,请检查系统环境变量并在系统变量路径中添加C:\windows\system32

如果您使用的是Windows,则按照以下方式运行命令,或者如果您得到错误“无法找到入口文件index.android.js”

mkdir android主要\ app \ src \ \资产 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

提出一个显而易见的建议,对我很有用。删除应用程序,重新启动服务器,重新从工具部署到设备。

在mac中也有同样的问题,在花了2天之后,我终于能够得到它的工作。

由于模拟器蜂窝数据被关闭,我得到了无法从assets index.android.bundle加载脚本,确保你的包正在运行。

确保你的模拟器蜂窝数据是打开的,通过做这个包服务器能够捆绑index.android.js。希望这对那些处于发展阶段的人有所帮助。