Android Gradle Group Common Properties

时间:2017-11-13 20:54:16

标签: android gradle android-gradle android-build-type

有没有办法将gradle属性分组重用?我可以通过重复属性来完成以下操作,但我试图通过将它们分组在一个公共位置来避免这种情况。我有以下构建类型

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

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

我已经定义了不同的口味,所以我不认为我可以将常见的属性放在不同的口味中。我希望我能够做一些像

这样的事情
def commonQaProps {
   applicationIdSuffix = ".qa"
   //Other properties
}

然后有

qa { commonQaProps }
qa2 { commonQaProps }

这样的事情可能吗?

1 个答案:

答案 0 :(得分:0)

如果您正在阅读文档,如果您正在构建一个buildType,则可以使用initWith

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

我仍然想知道分组属性是否可以在许多不相互继承的变体中使用。