Changing Build Variants In Bulk In AndroidStudio 3.0+
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.
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 projectreplace all occurrences of
<option name="SELECTED_BUILD_VARIANT" value="debug" />
with<option name="SELECTED_BUILD_VARIANT" value="release" />
or vice versa in alliml
files. Here is a one liner to change all modules torelease
: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:
You need a plugin called Build Variant Quick-Selector
Install Build Variant Quick-Selector (Settings->Plugins->Marketplace)
Build-> Switch All Build Variants...
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.
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
Post a Comment for "Changing Build Variants In Bulk In AndroidStudio 3.0+"