Skip to content Skip to sidebar Skip to footer

Changing Build Variants In Bulk In AndroidStudio 3.0+

Quick history: I'm using AndroidStudio 3.0 my project has 100+ modules (multiple applications and libraries). all of them have same flavorDimensions and flavors. Now question: ho

Solution 1:

There are two settings in Android Studio to enable switching all variants at once when selecting the app variant.

The settings are "Only sync the active variant" & "Do not build Gradle task list during Gradle sync". Both of them need to be disabled, then I restarted Android Studio once and Gradle sync.

Android Studio settings

With the settings in the screenshot disabled, I went from switching and waiting for ~10 seconds per dynamic-feature module (10 in my project) to one single switch in <5 seconds.

Note: This is tested in Android Studio 4.0.1


Solution 2:

Here is what I recently ended up doing:

  • close Android Studio

  • open a terminal

  • cd to the base directory of your project

  • replace all occurrences of <option name="SELECTED_BUILD_VARIANT" value="debug" /> with <option name="SELECTED_BUILD_VARIANT" value="release" /> or vice versa in all iml files. Here is a one liner to change all modules to release:

      find . -name \*.iml | xargs perl -pi -e 's/<option\s+name="SELECTED_BUILD_VARIANT"\s+value="[^"]+"/<option name="SELECTED_BUILD_VARIANT" value="release"/'
    
  • to change back to debug run:

      find . -name \*.iml | xargs perl -pi -e 's/<option\s+name="SELECTED_BUILD_VARIANT"\s+value="[^"]+"/<option name="SELECTED_BUILD_VARIANT" value="debug"/'
    
  • Open Android Studio again and do gradle sync

  • The build variant of all modules should be replaced now

Of course this approach makes assumptions about the formatting of an xml file which makes it a bit fragile. So far it seems to work well though.


Solution 3:


Solution 4:

I built the Build Variant Matrix Selector which, with all respect, I believe is faster to use than the ".. Quick Selector" mentioned above here. No duplicate drop downs, no hassle. Just select the variants from radio button in the matrix and go.

enter image description here


Solution 5:

Just extending Marten's answer. It's a bit tedious to use command line and not see what you're doing. Just use vscode or any other text editor of your choice.

  • First close Android Studio (because it can revert the changes back to original)
  • Search for *.iml files that has the text below. Just make sure to include any folders which are ignored from git. vscode seems to ignore searching folders and files that are defined in .gittignore
<option name="SELECTED_BUILD_VARIANT" value="debug" />

then replace it debug/release whatever you want.

  • Open Android Studio and see changes are applied

enter image description here


Post a Comment for "Changing Build Variants In Bulk In AndroidStudio 3.0+"