Changing build variants in bulk in AndroidStudio 3.0+

依然范特西╮ 提交于 2020-06-25 10:32:47

问题


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 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"/'
    
  • 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!