Issue
Currently I have the following network security config xml file:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<!-- default config that does not allow clear test -->
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<!-- trying to get debug override to change this -->
<debug-overrides cleartextTrafficPermitted="true (DOESN'T WORK)">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
All I am trying to do is conditionally enabled global domain clear traffic during development/debug mode.
I thought I had my answer when I discovered the tag <debug-overrides>...</debug-overrides>
.
Solution
Nevermind. I figured out how to do it using gradle runtime variables instead.
// In your app level gradle file `build.gradle`
android
{
...
buildTypes
{
debug
{
resValue "string", "clear_text_config", "true"
}
release
{
resValue "string", "clear_text_config", "false"
}
}
...
}
// In your network security configuration xml
<base-config cleartextTrafficPermitted="@string/clear_text_config">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
This works because gradle will automatically generate a resource file for you.
Answered By - AlanSTACK
Answer Checked By - Katrina (JavaFixing Volunteer)