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

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

我做错了什么?


当前回答

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

! android / app / src /调试

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

其他回答

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

在文件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__\/.*/
];

希望这能有所帮助。

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

默认情况下,一个名为“Metro server”的小型JavaScript服务器运行在端口8081上。

您需要使此端口可用于此服务器启动。所以,

释放端口 关闭虚拟设备 “react-native run-android”。

如何释放端口?

http://tenbull.blogspot.com/2019/05/how-to-kill-process-currently-using.html

如何在windows中杀死当前使用本地主机端口的进程?

最重要的是,我从8升级了我的节点版本。X到10.x(最新),正如facebook建议的那样 @ https://facebook.github.io/react-native/docs/getting-started

试试这个

taskkill /F /IM node.exe

然后

npx react-native run-android

如果你在linux上,从App根目录打开终端并运行

npm start

然后打开另一个终端窗口并运行:

react-native run-android