gpt4 book ai didi

android - 当我添加 networkSecurityConfig 标签时,React-native android 不会构建

转载 作者:行者123 更新时间:2023-12-04 23:55:20 25 4
gpt4 key购买 nike

正如我在这个 article 中发现的那样.
我想更新我的网络安全配置以允许来 self 的 android 模拟器的个人商店的根证书。但是当我这样做时,我不能再构建我的应用程序了。错误信息:

Unable to load script. Make sure you're either running a metro server (run 'react-native-start') or that your bundle 'index.android.bundle' is packaged correctly for release.

当我删除 android:networkSecurityConfig="@xml/network_security_config" 时,它再次运行良好..

有人知道怎么办吗?或者有其他方法来更改安全配置?

最佳答案

好的,终于找到了!! :)

React native 确实需要用于构建的明文流量。因此网络安全配置文件应包含:<base-config cleartextTrafficPermitted="true">

所以我在 src/debug/AndroidManifest.xml 中有一个标签

<application tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" 
android:networkSecurityConfig="@xml/react_native_config" />

并创建了一个文件 src/debug/res/xml/react_native_config.xml :

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="user"/>
<certificates src="system"/>
</trust-anchors>
</base-config>
</network-security-config>

关于android - 当我添加 networkSecurityConfig 标签时,React-native android 不会构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60328951/

25 4 0