How to have different network-security-config for different build variants?


I would like to trust certificate only in one build-variant. How to make it?


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>


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>


  • How to retain instance of fragment of fragment playing video after change in orientation?
  • Access sharepoint list from web site hosted externally from sharepoint
  • Manifest marge error after migrating to androidX
  • How to get slave status of mongodb using nodejs?
  • Java, How to refresh JTable in one frame from another frame
  • Add class to parent element
  • Chromedriver works manually but fails when ran from Jenkins Slave
  • Replace Windows command FTP -s:E:\\FtpScript.txt with SFTP? [duplicate]
  • OpenCv 2.4.3: can't find imread and SurfFeatureDetector::detect
  • java string index out of bound exception
  • Use animate() with series of levelplots in R raster
  • PhoneGap or Appcelerator Implementation
  • python Matplotlib candlestick plot works only on daily data, not for intraday
  • Google Data Studio MySql data source connection does not exist Error
  • Rails Template Error with Heroku
  • Is there a way to convert all existing table data to UTF8 collation?
  • iOS Today Extension created as .app rather than .appex
  • Difference between assigning instantiation to parent class and derived class
  • Forward slash vs backward slash for file path in git bash
  • device tree overlay phandle
  • Angular 6 illegal operation on a directory, open '/Users//.npm-global/lib/node_modules/
  • Hyperlink to Outlook Attachment
  • How to manipulate content of a comment with Apache POI
  • Google Compute instance receiving email
  • Problems with special characters in php soap client
  • Backbone - Create Multiple Models in Collection - serverside
  • Pandas time series data Index from a string to float [duplicate]
  • Create an average of multiple excel chart without the data source
  • Is there a better way for handling SpatialPolygons that cross the antimeridian (date line)?
  • Can a PHP script be scheduled to run at a specific time or after a specific amount of time has expir
  • how to run ejabberd with Erlang on Heroku?
  • How to call jQuery function in HTML returned by AJAX
  • How to use Streams api peek() function and make it work?
  • How do I add a mouse over tooltip to an Image using .DrawImage()
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • How to warp text around image in iOS?
  • How to use FirstOrDefault inside Include
  • PHP Permalinks.. how to change?
  • Running R's aov() mixed effects model from Python using rpy2
  • ReferenceError: TextEncoder is not defined