在现有的android应用中运行RN View会显示错误无法加载脚本

时间:2020-08-05 12:59:52

标签: javascript android react-native react-native-android metro-bundler

我已将现有的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

并运行该应用程序,它运行正常。

我也可以在此网址上看到捆绑包

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

知道我缺少什么吗?

Errror

我正在模拟器中运行应用程序,而不是在飞行模式下。

Development server up on 8081

捆扎机这样打开,但是在单击RR时,它显示No apps connected(请参见图片)

Metro bundler

1 个答案:

答案 0 :(得分:1)

尝试了此answer中的大多数选项后,没有任何选项起作用。对我有用的是将以下代码添加到<network-security-config>文件中的network_security_config.xml

<?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>