我正在尝试使用Android文档来使用自定义证书here。所需的网络配置文件是:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="@raw/extracas"/>
<certificates src="system"/>
</trust-anchors>
</base-config>
</network-security-config>
我已经创建了network_security_config.xml,并将参考文献android:networkSecurityConfig="@xml/network_security_config"
添加到我的表现中。我有.crt文件,我需要包括但我有两个问题:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="@raw/cert_cubic_trusted_ca-sha256.crt"/>
<certificates src="system"/>
</trust-anchors>
</base-config>
</network-security-config>
我得到一个红色的波形,错误“缺少src资源。”,当我尝试构建时,构建日志输出错误:
AGPBI: {"kind":"error","text":"error: resource raw/certname.crt (aka com.comname.appname:raw/certname.crt) not found.","sources":[{"file":"/Users/205314/project/appname/app/src/main/res/xml/network_security_config.xml","position":{"startLine":5}}],"original":"","tool":"AAPT"}
:app:processDebugResources
:app:processDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Failed to process resources, see aapt output above for details.
我不知道为什么我无法从XML引用我的原始资源文件夹中的资产或在其中创建一个文件夹,这似乎是我最大的问题。我可以在代码中使用R.raw引用原始资源,但我从来不需要使用@raw引用,我不确定为什么它没有按照描述工作。
根据Accessing resources documentation,资源名称是
文件名,不包括扩展名
所以你需要从你的.crt
中删除src
:
<certificates src="@raw/cert_cubic_trusted_ca-sha256"/>