androidgradleandroid-gradle-pluginandroid-build-type

Android Gradle Group Common Properties


Is there a way to group gradle properties to be reused? I can accomplish the following by having duplicate properties but I am trying to avoid this by grouping them in a common place. I have the following build types

buildTypes {
    debug {}
    qa {
        applicationIdSuffix = ".qa" //Duplicate
    }
    qa2 {
        applicationIdSuffix = ".qa" //Duplicate
    }
    release {} 
}

flavors { 
    flagship {}
    other1 {}
    other2 {}
}

I already have different flavors defined so I don't think I can place the common properties in different flavors. I was hoping I'd be able to do something like

def commonQaProps {
   applicationIdSuffix = ".qa"
   //Other properties
}

and then have

qa { commonQaProps }
qa2 { commonQaProps }

Is something like this possible?


Solution

  • After reading the documentation if you're building one buildType off of another you can use initWith.

    buildTypes {
        debug {}
        qa {
            applicationIdSuffix = ".qa" //Duplicate
        }
        qa2 {
            initWith qa
            //Customize other properties here
        }
        release {} 
    }
    

    I still would like to know if grouping properties is possible to use in many variants that don't inherit from each other.