react-native android:安全设置正在阻止 Metro 服务器

react-native android: security settings are blocking Metro server

我正在尝试使用 Facebook Audience Network 设置 Admob 中介。教程在这里 https://developers.facebook.com/docs/audience-network/android-network-security-config

建议我修改我的 Android 安全配置:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
...
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">127.0.0.1</domain>
</domain-config>
...
</network-security-config>

但是当我这样做时,我的应用程序在开发模式下停止工作:

Metro 服务器是 运行。我完全可以从我的手机 Chrome 访问 http://127.0.0.1:8081。只是此安全设置阻止我的应用程序从此地址获取 JS 包。

目前我在开发应用程序时禁用此安全配置,并在构建生产包时再次启用它,但这不是长期可持续的。

我该如何解决这个问题?

添加这个

<domain includeSubdomains="true">localhost</domain>

有帮助