Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot reference raw resources from Network Security Configuration XML

I'm trying to follow the Android documentation for using custom certs here. The desired network config file is:

<?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>

I have already created network_security_config.xml and have added the reference android:networkSecurityConfig="@xml/network_security_config" to my manifes. I have .crt files I need to include but I am having two problems:

  1. I cannot create a directory in my raw folder, when I do, it creates the directory in my file system but not in my raw resource directory in the project.

  2. In lieu of a directory I just reference my .crt files directly in the raw folder, but when I try to reference the certs, here's my network_security_config.xml

    <?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>
    

I get a red squiggle with error "missing src resource.", and when I attempt to build, the build log outputs error:

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.

I do not know why I am unable to reference assets in my raw resource folder from XML or create a folder within it, this seems to be my biggest issue. I can reference raw resources with R.raw in code but I have never needed to reference using @raw and I'm not sure why it isn't working as described.

like image 543
ThePartyTurtle Avatar asked Mar 12 '19 20:03

ThePartyTurtle


1 Answers

As per the Accessing resources documentation, the resource name is

the filename, excluding the extension

So you need to remove the .crt from your src:

<certificates src="@raw/cert_cubic_trusted_ca-sha256"/>
like image 147
ianhanniballake Avatar answered Oct 26 '22 14:10

ianhanniballake