运行 现有 android 应用程序中的 RN 视图给出错误无法加载脚本

Running RN View in existing android app gives error Unable to load script

我已经将现有的 android 应用程序集成到 React Native 应用程序中。当我 运行 使用 react native cli 时,它会打开应用程序,并在单击按钮打开 RN 视图后出现错误 Unable to load script Make sure you are either running a Metro server or that your bundle 'index.android.bundle' is packaged correctly for release(参考图片)

如果我使用命令

手动创建 index.android.js

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

和 运行 应用程序,它工作正常。

我也可以看到这个 url

http://localhost:8081/index.bundle?platform=android&dev=true&minify=false

知道我遗漏了什么吗?

我在模拟器中 运行ning 应用程序,它没有处于飞行模式。

Bundler 是这样打开的,但是在点击 RR 时,它显示 No apps connected(参考图片)

在尝试了此 answer 中的大部分选项后,没有一个选项有效。对我有用的是将以下代码添加到 network_security_config.xml 文件中的 <network-security-config>

<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:tools="http://schemas.android.com/tools">

    <!-- This is only for debuggable versions of the App that use Charles Proxy
      https://www.charlesproxy.com/documentation/using-charles/ssl-certificates/ -->
    <debug-overrides>
        <trust-anchors>
            <!-- Trust user added CAs while debuggable only -->
            <certificates src="user" />
        </trust-anchors>
    </debug-overrides>
    <base-config cleartextTrafficPermitted="false" />
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">127.0.0.1</domain>
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">10.0.2.2</domain>
        <domain includeSubdomains="true">10.0.3.2</domain>
    </domain-config>
 </network-security-config>