React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
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。
其他回答
如果你已经尝试了上述解决方案中的所有方法,可以尝试以下步骤:
在android/app/src/main/assets中创建文件 执行如下命令:
React-native bundle——platform android——dev false——entry-file index.js——bundle-output android/app/src/main/assets/index.android。Bundle——assets-dest android/app/src/main/res
现在运行命令构建react-native run-android
对我来说,这个错误是由react-native的升级引起的
从Android 9.0 (API级别28)开始,默认情况下禁用明文支持。
如果您检查了升级差异,您需要创建一个调试清单 android / app / src /调试/ AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
</manifest>
查看更多信息:https://stackoverflow.com/a/50834600/1713216
https://react-native-community.github.io/upgrade-helper/
我的解决方案如下:
启动Metro服务器
$ react-native start
开始安卓
$ react-native run-android
如果看到错误提示“端口8081已被使用”,那么您可以终止该进程并重新运行
$ react-native start
参见React Native故障诊断页面。
我得到了同样的问题,在遵循以下步骤后,它得到了解决的问题
清晰的守望人守望:守望人守望一切。 删除“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-*
试试下面的方法。
删除Android和IOS文件夹 运行react-native eject 运行react-native Run -android
也许在前面的步骤之后,你执行了npm start -——reset-cache
我有工作,希望能帮到你。