React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
类似的问题也发生在我身上。 显然Mcafee阻塞了8081端口。我花了好几个小时才弄明白。
尝试运行:
react-native run-android --port=1234
当应用程序在模拟器上显示错误时,进入开发设置(Ctrl+M)。
将“调试服务器主机和设备端口”更改为“localhost:1234”。
关闭应用程序,并从应用程序抽屉启动它。
其他回答
我只是想补充一个这里没有提到的不明显的可能性。我正在使用@react-native-community/netinfo来检测网络变化,主要是网络状态。为了测试网络关闭状态,需要关闭模拟器上的WIFI开关。这也有效地切断了模拟器和调试环境之间的桥梁。测试结束后,我没有重新开启WIFI,因为我离开了电脑,回来后很快就忘了这事。
其他人也有可能是这种情况,在采取任何其他激烈步骤之前,值得检查一下。
试试下面的方法。
删除Android和IOS文件夹 运行react-native eject 运行react-native Run -android
也许在前面的步骤之后,你执行了npm start -——reset-cache
我有工作,希望能帮到你。
你也可以把node js降级到小于12的版本,然后删除nodemodule,然后再次运行NPM install
在我的例子中,我试图在模拟器上运行应用程序。但是,我得到了这个
这个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。
对我有用的是:
关闭所有控制台 打开一个新的控制台 $ adb设备 确保你只连接了一个设备 $ react-native run-android