Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The network_security debugBuild feature can be implemented by defining a custom XML configuration file using the Network Security Config resource.

Firstly, create an XML file called networksecurityconfig.xml and add the following lines of code:

<network-security-config>
    <debug-overrides>
        <trust-anchors>
            <!-- debug-only root CA certificate -->
            <certificates src="user"
                android:certificateSubjectPublicKeyInfo="...">
        </trust-anchors>
    </debug-overrides>
</network-security-config>

In the above code, the <trust-anchors> element specifies a root CA certificate source for the app to trust during debug builds. The certificateSubjectPublicKeyInfo parameter should be replaced with the subject public key of the root CA you wish to trust.

Next, add this resource file to your app's res/xml/ directory.

Finally, in your app's build.gradle file, add the following line of code to attach the network security config resource to your app:

android {
    ...
    buildTypes {
        debug {
            ...
            manifestPlaceholders = [
                network_security_config: "@xml/network_security_config"
            ]
        }
    }
}

In the above code, the networksecurityconfig parameter specifies the location of the networksecurityconfig.xml file. This file will be included in the debug build of your app.

By utilizing the Network Security Config resource in this manner, you can ensure that your app is protected against unauthorized network activity during the debug build process.