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

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

我做错了什么?


当前回答

这个错误突然出现在我面前,而我解决它的方法是:

Android Studio中的AVD管理器 在虚拟设备的操作下按下箭头 擦除数据 重新启动地铁

其他回答

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

从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">

对我来说,这个错误是由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使用NPM和Node版本的某些组合时出现了问题。

你有两个选择:

Alternative 1: Try to update or downgrade npm and node version. Alternative 2: Go to this file: \node_modules\metro-config\src\defaults\blacklist.js and change this code: var sharedBlacklist = [ /node_modules[/\\]react[/\\]dist[/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; and change to this: var sharedBlacklist = [ /node_modules[\/\\]react[\/\\]dist[\/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; Please note that if you run an npm install or a yarn install you need to change the code again.

对我有用的是:

关闭所有控制台 打开一个新的控制台 $ adb设备 确保你只连接了一个设备 $ react-native run-android