I would like to trust certificate only in one build-variant. How to make it?Answer1:
Create a source for the variant. Create a
res/xml/ directory in that source set, and put your network security configuration XML in there. Create other stuff in that source set as needed (e.g.,
res/raw/ and your certificate). In that source set, create an
AndroidManifest.xml file, with an
<application> element that just has the
android:networkSecurityConfig attribute and nothing else.
And you should be done.
Builds for this variant will include your source set, merge in the
android:networkSecurityConfig attribute, and leverage the resources tied to it. Builds for other variants will ignore this source set, leaving you without a network security configuration.
Just create 'n' number of customized network security XML for your 'n' number of build variant, and then you can inject exact network security XML file to your Android Manifest XML depend on the Environment. see here for examples <a href="https://developer.android.com/studio/build/manifest-build-variables" rel="nofollow">https://developer.android.com/studio/build/manifest-build-variables</a>Answer3:
You can create build_variant folder inside src and your network_config file inside that
below is some sample for different icon for different build_variant. same way we can do for network_config file
<a href="https://i.stack.imgur.com/q8EnF.png" rel="nofollow"><img alt="Exmaple" class="b-lazy" data-src="https://i.stack.imgur.com/q8EnF.png" data-original="https://i.stack.imgur.com/q8EnF.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>