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

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

我做错了什么?


当前回答

(快速回答)

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

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

其他回答

我也遇到过类似的问题。NPX react-native init创建。gitignore文件,忽略<project>/android/app/src/debug文件夹。如果您稍后克隆了此项目,则该文件夹将会丢失。 解决办法很简单。以后将这一行添加到.gitignore文件的底部。

! android / app / src /调试

对于当前项目,请项目创建者提交此文件夹。 我在react原生版本0.63中遇到过这个错误

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

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

你可以尝试以下方法:

在AndroidManifest.xml中添加这一行

<application
[...]
android:usesCleartextTraffic="true"
/>
[...]
</application>

编辑: 注意,为了应用程序的安全性,在生产环境中它必须为假

在地铁黑名单中更新此部分

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

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

尝试运行:

react-native run-android --port=1234

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

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

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