问题
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: how to change flavors for all modules in bulk in AndroidStudio 3.0+ without changing each application separately?
回答1:
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"/'
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.
来源:https://stackoverflow.com/questions/48279761/changing-build-variants-in-bulk-in-androidstudio-3-0