React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:

无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。

我做错了什么?


当前回答

在我的例子中,我在模拟器中设置了一个代理。 它在我删除代理后恢复正常。

其他回答

在我的例子中,我试图在模拟器上运行应用程序。但是,我得到了这个

这个IP 10.0.2.2可以从模拟器chrome浏览器访问。问题是这个IP不在Android网络安全设置白名单中。所以,无论你在这里看到的IP地址添加到下面的设置,你就可以开始了。

./android/app/src/main/AndroidManifest.xml

        <application
                android:name=".MainApplication"
+               android:usesCleartextTraffic="true"   <- Add this line
                android:allowBackup="true"
                android:label="@string/app_name"
                android:icon="@mipmap/ic_launcher"

./android/app/src/main/res/xml/network_security_config.xml
</network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">10.0.1.1</domain>
        <domain includeSubdomains="true">10.0.2.2</domain>
        <domain includeSubdomains="true">10.0.3.2</domain>
    </domain-config>
 </network-security-config>

只需将<domain inclesubdomains ="true">10.0.2.2</domain>替换为react-native错误中显示的IP。

你还没有启动捆扎机呢。在项目的根目录下运行npm start或react-native start,然后再执行react-native Run -android。

在数小时寻找答案之后。解决方案是将节点降级到版本12.4。

在我的例子中,我意识到这个错误只发生在节点版本12.6的react native 0.60版本中。

以下是我在不改变构建的情况下解决这个问题的方法:

1-关闭虚拟设备

2-在物理设备上测试-(它工作)

3-创建新的虚拟设备API 30 Android 10+

4-在新创建的虚拟设备上再次尝试,所有工作都像一个魅力。

你可以尝试以下方法:

在AndroidManifest.xml中添加这一行

<application
[...]
android:usesCleartextTraffic="true"
/>
[...]
</application>

编辑: 注意,为了应用程序的安全性,在生产环境中它必须为假