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

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

我做错了什么?


当前回答

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

其他回答

对我有用的是:

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

我做了: react-native开始 而且 NPX react-native run-android。

然而,对于Min19,(基于Ubuntu的)我也有同样的问题,直到我运行:

echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

来自: https://reactnative.dev/docs/troubleshooting#content

至少我手机里还有软件在运行。

我尝试了下面所有的解决方案,不同的人评论和回答。有时它工作,但有时没有一个解决方案为我工作.....此错误的最佳解决方案从物理设备卸载APK并再次运行应用程序…它100%适合我!!

步骤1 -

从物理设备上卸载APK

步骤2 -

进入Android文件夹cd Android

步骤3 -

输入命令Gradlew Clean

步骤4 -

输入Cd . .返回项目

步骤4 -

执行命令npx react-native Run -android或react-native Run -android

对我有效的解决方案如下:

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
]; 

(快速回答)

在我的工作空间尝试解决这个问题后,我找到了一个解决方案。

此错误是因为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.