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

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

我做错了什么?


当前回答

我也有同样的问题。但是这个方法解决了这个问题。 进入android文件夹使用 CD android然后gradlew clean或。/gradlew clean,以适用于你的操作系统的为准。

其他回答

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

这个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。

从Android 9.0 (API级别28)开始,默认情况下禁用明文支持。

如果您正确地执行正常运行命令,那么您需要这样做来消除这个问题

npm安装 react-native开始 react-native运行android

然后像这样修改你的android manifest文件。

<application
    android:name=".MainApplication"
    android:icon="@mipmap/ic_launcher"
    android:usesCleartextTraffic="true" // add this line with TRUE Value.
android:theme="@style/AppTheme">

M1芯片

验证您的JAVA_HOME路径,在我的M1芯片的情况下,我将其定义为.zprofile

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"

然后执行source ~/。终端z型线

在这之后,它对我起作用了。

在地铁黑名单中更新此部分

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

试试下面的方法。

删除Android和IOS文件夹 运行react-native eject 运行react-native Run -android

也许在前面的步骤之后,你执行了npm start -——reset-cache

我有工作,希望能帮到你。