首页 > 解决方案 > 网络安全配置期望系统、用户或@resource 值

问题描述

我目前正在尝试为 AndroidTV/FireTV 设置 Charles 代理服务,但在 res/xml/network_security_config.xml 中指定证书颁发机构时遇到问题

<network-security-config>
    <debug-overrides>
        <trust-anchors>
            <!-- Trust user added CAs while debuggable only -->
            <certificates src="@raw/my_ca" />
        </trust-anchors>
    </debug-overrides>
</network-security-config>

每次我尝试输入 @raw 时,我的 IDE 都会自动完成 appNs(应用程序命名空间)。我已经尝试过无效/重启、清理/重建、添加 appNs、在 gradle 的 sourceSets 中指定 raw、检查 compileSDK/build 工具的更新(在 android 中配置网络安全 xml 时出错),但应用程序仍然拒绝解决我的资源。

编辑:虽然资源 ID 未解析,但应用程序仍会在运行时编译并崩溃,并出现以下错误:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.my.package, PID: 29431
java.lang.RuntimeException: Unable to create application com.my.package.tv.ui.TVAppClass: java.lang.RuntimeException: Failed to parse XML configuration from network_security_config
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5881).

其次是...

Caused by: android.security.net.config.XmlConfigSource$ParserException: Unknown certificates src. Should be one of system|user|@resourceVal at: Binary XML file line #6
    at android.security.net.config.XmlConfigSource.parseCertificatesEntry(XmlConfigSource.java:211)
    at android.security.net.config.XmlConfigSource.parseTrustAnchors(XmlConfigSource.java:226)
    at android.security.net.config.XmlConfigSource.parseConfigEntry(XmlConfigSource.java:280)
    at android.security.net.config.XmlConfigSource.parseNetworkSecurityConfig(XmlConfigSource.java:350)
    at android.security.net.config.XmlConfigSource.ensureInitialized(XmlConfigSource.java:101)

它可以使用“系统”或“用户”值正常运行,但 Charles 的 SSL 代理将不起作用。

设备元:

标签: androidcharles-proxy

解决方案


推荐阅读