android - 网络安全配置期望系统、用户或@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 代理将不起作用。
设备元:
- 安卓工作室 3.3
- 构建 #AI-182.5107.16.33.5199772,构建于 2018 年 12 月 24 日
- JRE:1.8.0_152-release-1248-b01 x86_64
- 虚拟机:JetBrains sro 的 OpenJDK 64 位服务器虚拟机
- macOS 10.12.6
- compileSdkVersion 28
- 构建工具版本 28.0.3
解决方案
推荐阅读
- bitwise-operators - 为什么〜x = -x -1
- ios - 如何根据设备方向制作横向或纵向照片
- python-3.x - 带有波斯语标签的网页抓取
- linux - 安装 g++-7:未满足的依赖项
- firebase - 在 Azure 中有后端的应用程序中使用 Firebase 身份验证?
- amazon-web-services - 部署后带有计划事件的 Lambda 函数行为
- android - 如何在折线图 MPAndroid 图表中设置曲线颜色
- python - 将键发送到 selenium python 中的输入字段时出现错误:(元素不可交互)
- opencl - OpenCL 内核代码编译错误 - Visual Studio 2019
- typescript - 循环中的多个离子载玻片无法在载玻片上提供正确的索引