Bri*_*ian 21 gradle android-studio build.gradle android-gradle-plugin android-productflavors
我有一个应用程序的两个维度,然后调用绿色和蓝色.只有这两个维度,但无限数量的产品口味.这是我在gradle中设置它的方式
flavorDimensions "green", "blue"
productFlavors {
one {
applicationId "com.app.green.one"
versionCode 1
versionName "1.0.0.1";
flavorDimension = "green"
}
two {
applicationId "com.app.blue.two"
versionCode 6
versionName "1.0.1";
flavorDimension = "blue"
}
}
Run Code Online (Sandbox Code Playgroud)
但是在我同步gradle之后,在构建变体选项卡中,我看到的是oneTwoDebug和oneTwoRelease,我应该看到greenOneDebug greenOneRelease,blueTwoDebug,blueTwoRelease
从理论上讲,我想将它扩展为类似的东西
one {
applicationId "com.app.green.one"
versionCode 1
versionName "1.0.0.1";
flavorDimension = "green"
}
two {
applicationId "com.app.blue.two"
versionCode 6
versionName "1.0.1";
flavorDimension = "blue"
}
three {
applicationId "com.app.green.three"
versionCode 1
versionName "1.0.0.1";
flavorDimension = "green"
}
four {
applicationId "com.app.blue.four"
versionCode 6
versionName "1.0.1";
flavorDimension = "blue"
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,尺寸代表app的"类型",然后风味更适合可以添加的组织.
**编辑我错误地设置了gradle,这里指出的是对我所拥有的更准确的描述
flavorDimensions "type", "organization"
productFlavors {
blue {
applicationId "com.app.blue"
flavorDimension = "type"
versionCode 6
versionName "1.0.1";
}
red {
applicationId "com.app.red"
flavorDimension = "type"
versionCode 1
versionName "1.0.0.1";
}
company1 {
flavorDimension = "organization"
}
company2 {
flavorDimension = "organization"
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止这是有效的,所以我可以创建用于切换类型的java源目录,但是如果我想要组织特定的配置文件,我也为每个组织创建java源目录吗?
ben*_*n75 35
我认为你误解了flavorDimension的概念.
flavorDimension类似于风味类别,每个维度的风味的每个组合都会产生一个变体.
在您的情况下,您必须定义一个名为"type"的flavorDimension和另一个名为"organization"的维度.对于"组织"维度中的每种风味,它将产生所有可能的"类型"(或双重配方:对于每种"类型",它将为每个组织产生变体).
风味尺寸定义了将用于生产变体的笛卡尔积.
编辑:我将尝试用伪gradle代码说明:
让我们来定义一些"类型":青铜,银和金
让我们定义一些组织:customerA,customerB,customerC
所有这些都是productFlavors,但它们属于两个不同的维度:
flavorDimensions("type_line", "organization")
productFlavors {
gold {
...
dimension = "type_line"
}
silver {
...
dimension = "type_line"
}
bronze {
...
dimension = "type_line"
}
customerA {
...
dimension = "organization"
}
customerB {
...
dimension = "organization"
}
customerC {
...
dimension = "organization"
}
}
Run Code Online (Sandbox Code Playgroud)
此配置将生成18(3*3*2)个变体(如果您有2个标准构建类型:debug和release):
gold-customerA-debug; gold-customerA-release; gold-customerB-debug; gold-customerB-release; gold-customerC-debug; gold-customerC-release;
silver-customerA-debug; silver-customerA-release; silver-customerB-debug; silver-customerB-release; silver-customerC-debug; silver-customerC-release;
...(青铜相同)
请注意,维度的名称完全是任意的,对变体名称没有影响.
风味尺寸非常强大,但是如果你使用太多它们:它会导致变体数量呈指数级增长(后期构建清理任务可能对删除无用或无意义的变体很有用)
| 归档时间: |
|
| 查看次数: |
12771 次 |
| 最近记录: |