Define a variable in build.gradle and use that value in network XML file

Viewed 207

In build.gradle file I have to define a boolean value

buildConfigField("boolean", "SKIP_SSL_CHECK", "true")

so I want o access it in the network.xml file

 <?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="${SKIP_SSL_CHECK}" /
    <debug-overrides>
        <trust-anchors>
            <certificates src="user" />
        </trust-anchors>
    </debug-overrides>
</network-security-config>

i want to make that value alter as per the build variant for debug, it should be true and for others, it should be false.

Thanks in advance

1 Answers

Unfortunately, there is no option for manifest placeholders or other types of variables in XML resources.

However, you can have multiple versions of the resource in source sets tied to specific build variants, with different values for cleartextTrafficPermitted:

  • In app/src/debug/res/xml/, put the debug version of your resource
  • In app/src/main/res/xml/, put the release version of your resource
Related