我有两个风味维度:brand
和version
,我的风味配置如下:
flavorDimensions 'brand', 'version'
Brand1 {
dimension 'brand'
...
}
Brand2 {
dimension 'brand'
...
}
Version1 {
dimension 'version'
...
}
Version2 {
dimension 'version'
...
}
我想为每个配置使用四个唯一的buildConfigField
-s(例如HockeyAppId):
我该怎么做?
答案 0 :(得分:0)
所以这很简单。您可以根据口味或发布类型进行修改,而无需付出任何努力。
如果您试图在多个维度上重用某个风味,那不是其所需的功能。风味是指该应用的内置编译打包版本。并不是真正要作为一组通用参数。因此,您需要为每种差异提供一种风味,例如
尺寸为1的flavor1->
flavor1Dimension2->尺寸2
维度1中的flavor2->
flavor2Dimension2->尺寸2等。
在这里,我将举例说明使用动态
当然,您可以做的更多,但这应该可以帮助您完成请求。
flavorDimensions 'default', 'secondary'
productFlavors {
a35Demo {
dimension 'default'
applicationId "com.appstudio35.yourappstudio.demo"
buildConfigField "int", "BUSINESS_ID", "1"
resValue "string", "app_name", "App Studio 35"
buildConfigField "String", "NOTIFICATION_ICON", '"ic_launcher"'
manifestPlaceholders = [iconPath:"@mipmap/ic_launcher", roundIconPath:"@mipmap/ic_launcher_round"]
}
smallville {
dimension 'secondary'
applicationId "com.appstudio35.yourappstudio.smallville"
buildConfigField "int", "BUSINESS_ID", "22"
resValue "string", "app_name", "Smallville"
buildConfigField "String", "NOTIFICATION_ICON", '"ic_launcher_smallville"'
manifestPlaceholders = [iconPath:"@mipmap/ic_launcher_smallville", roundIconPath:"@mipmap/ic_launcher_round_smallville"]
}
}
buildTypes {
debug {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "SERVER_URL", '"https://api.dev.myurl.com"'
shrinkResources false //remove unused resources per flavor
minifyEnabled false
}
release {
buildConfigField "String", "SERVER_URL", '"https://api.prod.myurl.com"'
shrinkResources true //remove unused resources per flavor
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//production builds
productFlavors.a35Demo.signingConfig signingConfigs.releaseA35YourAppStudio
productFlavors.smallville.signingConfig signingConfigs.releaseA35YourAppStudio
}
}
快乐编码!
答案 1 :(得分:0)
为此,我编写了自己的插件:https://github.com/nikialeksey/porflavor,现在可以定义以下字段:
flavorDimensions 'brand', 'version'
productFlavors {
Brand1 {
dimension 'brand'
...
}
Brand2 {
dimension 'brand'
...
}
Version1 {
dimension 'version'
...
}
Version2 {
dimension 'version'
...
}
}
apply plugin: 'com.nikialeksey.porflavor'
porflavor {
Brand1Version1 {
buildConfigField "boolean", "fooFeatureEnabled", "false"
}
Brand2Version2 {
buildConfigField "boolean", "fooFeatureEnabled", "true"
}
...
}