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

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

我做错了什么?


当前回答

你可以尝试以下方法:

在AndroidManifest.xml中添加这一行

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

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

其他回答

我做了: 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

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

显然,没有一个答案能帮我解决这个问题。我能够在模拟器上运行反应本机应用程序,但相同的代码(即使服务器正在运行),在设备上运行应用程序时给了我这个错误。

我能够通过在终端中执行以下命令来解决它:

Adb reverse tcp:8081 tcp:8081

我在学习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。

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

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

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