Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 203
Subham Naik Avatar asked Oct 27 '25 22:10

Subham Naik


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
like image 200
CommonsWare Avatar answered Oct 29 '25 15:10

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!