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

我得到:

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

我使用的命令:

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


当前回答

在我的例子中,我已经从MainApplication.java中删除了以下一行。(这是我之前错误添加的):-

进口com.facebook.react.BuildConfig;

之后,清洁项目和点击命令

react-native运行android

其他回答

我认为在所有其他解决方案之前,首先要做的是:

1. 检查您的设备是否在线?

2. 如果您在真实设备上运行应用程序,那么该设备应该与运行开发服务器的网络相同。

更多信息请访问本页。

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

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

它应该会起作用。

好运!

就我而言,我忘了Android模拟器的wifi是禁用的。 为了解决这个问题,我只是向下滑动通知栏来展开菜单并启用Wifi连接。

激活Wifi连接后,我的问题就解决了。

如果已经尝试了以上所有解决方案,但仍然遇到错误。 试着和我一样配置你的genymotion:

我在真正的android设备上也遇到过同样的问题。

解决方案:基于Niltoid的回答

查找本地IP 打开应用程序,摇晃你的安卓设备 去开发设置和>调试服务器… 粘贴你的IP和端口;X.X.X.X:8088"(其中X是您的本地IP)

Mac用户:打开你的网络首选项,在这里你会得到你的本地IP。