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

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

我做错了什么?


当前回答

如果你在Linux操作系统上运行,可能会出现npm远程服务器不运行的情况。打开另一个终端(带有项目目录),在执行sudo react-native run-android之前,运行sudo npm start或sudo react-native start命令

其他回答

类似的问题也发生在我身上。 显然Mcafee阻塞了8081端口。我花了好几个小时才弄明白。

尝试运行:

react-native run-android --port=1234

当应用程序在模拟器上显示错误时,进入开发设置(Ctrl+M)。

将“调试服务器主机和设备端口”更改为“localhost:1234”。

关闭应用程序,并从应用程序抽屉启动它。

试试这个命令

~/Library/Android/sdk/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081

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

我得到了同样的问题,在遵循以下步骤后,它得到了解决的问题

清晰的守望人守望:守望人守望一切。 删除“node_modules”文件夹:rm -rf node_modules && npm install。 Reset Metro Bundler cache: rm -rf /tmp/ Metro - Bundler -cache-* 删除急速缓存:rm -rf /tmp/急速-map-react-native-packager-*

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

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