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

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

我做错了什么?


当前回答

在尝试了几种方法后,这对我来说很有效。

在文件node_modules\metro-config\src\defaults\blacklist.js中

替换:

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

:

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

希望这能有所帮助。

其他回答

你也可以把node js降级到小于12的版本,然后删除nodemodule,然后再次运行NPM install

类似的问题也发生在我身上。 显然Mcafee阻塞了8081端口。我花了好几个小时才弄明白。

尝试运行:

react-native run-android --port=1234

当应用程序在模拟器上显示错误时,进入开发设置(Ctrl+M)。

将“调试服务器主机和设备端口”更改为“localhost:1234”。

关闭应用程序,并从应用程序抽屉启动它。

M1芯片

验证您的JAVA_HOME路径,在我的M1芯片的情况下,我将其定义为.zprofile

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"

然后执行source ~/。终端z型线

在这之后,它对我起作用了。

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

我在学习React Native教程时也遇到过同样的问题(在Linux上开发,目标是Android)。

这个问题帮助我通过以下步骤解决了问题。按如下顺序执行以下命令:

(在项目目录)mkdir 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运行android

您可以通过将上述步骤放在包的脚本部分来自动化它们。Json是这样的:

"android-linux": "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"

然后你可以每次都从你的命令行执行npm run android-linux。