Search code examples
androidgradleandroid-productflavorsandroid-build-flavorsandroid-flavors

Keep flavors configs in separate .gradle files


Being short - is there a way to keep flavor configs in separate .gradle files?

And for more details - I'd like to have per flavor .gradle files (like flavorGermany.gradle, flavorUkraine.gradle, flavorItaly.gradle etc.) that will be included with 'apply from:' directive into main gradle. Each flavor .gradle will contain signing and build configs.


Solution

  • Sure you can. Just place those files in app folder and then in your app folders build.gradle import those.

    Your flavorGermany.gradle would look like this:

    android {
        productFlavors {
            flavorGermany {}
        }
    }
    

    And then you import those in your build.gradle (app):

    apply plugin: 'com.android.application'
    apply from: 'flavorGermany.gradle'
    apply from: 'flavorUkraine.gradle'