React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
在数小时寻找答案之后。解决方案是将节点降级到版本12.4。
在我的例子中,我意识到这个错误只发生在节点版本12.6的react native 0.60版本中。
其他回答
从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">
下面这些步骤真的对我很有帮助:
步骤1:在android/app/src/main/assets目录下创建一个目录
Linux命令:mkdir android/app/src/main/assets
第二步:将index.android.js(在根目录下)重命名为index.js(也许有一个index.js文件,在这种情况下你不需要重命名它),然后运行以下命令:
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
步骤3: 构建APK: react-native run-android
请在最新版本使用index.js。
享受:)
在我的例子中,我试图在模拟器上运行应用程序。但是,我得到了这个
这个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。
类似的问题也发生在我身上。 显然Mcafee阻塞了8081端口。我花了好几个小时才弄明白。
尝试运行:
react-native run-android --port=1234
当应用程序在模拟器上显示错误时,进入开发设置(Ctrl+M)。
将“调试服务器主机和设备端口”更改为“localhost:1234”。
关闭应用程序,并从应用程序抽屉启动它。
你也可以把node js降级到小于12的版本,然后删除nodemodule,然后再次运行NPM install