Merge NetworkSecurityConfig xml files in Manifest

Viewed 1309

In my application I set a network security configuration file with the following:

<network-security-config>
    <debug-overrides>
        <trust-anchors>
            <certificates src="user" />
        </trust-anchors>
    </debug-overrides>
</network-security-config>

I'm setting in my manifest this way:

  <application 
             (...)
              android:networkSecurityConfig="@xml/network_security_config">

Additionally, I'm adding a 3rd party lib which supplies its own network security config file with a set of domains

<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">domainA</domain>
    </domain-config>
</network-security-config>

Which they are setting in my manifest this way:

  <application android:networkSecurityConfig="@xml/network_security_config">

The problem is that the manifest merge only works in manifest.xml file (afaik), therefore the netowrk-security-config file will always be the application file and not the merge between the app and 3rd party network-security-config files, is there a way to achieve something like this?

<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">domainA</domain>
    </domain-config>
     <debug-overrides>
        <trust-anchors>
            <certificates src="user" />
        </trust-anchors>
    </debug-overrides>
</network-security-config>
1 Answers

There is no built-in mechanism to merge resources that way. You would need to have the combined network security configuration file in your app module, where you manually merge what you need and what the library requests.

Related