Ответ 1
Я нашел решение:
Сначала вместо def test
укажите новое поле для всех productFlavors
productFlavors.all {
ext.dTest = null
}
Затем это поле устанавливается в каждом аромате (код не изменяется)
productFlavors {
flavorA {
dTest = 1
}
flavorB {
dTest = 2
}
}
И, наконец, вы можете сделать это в buildTypes
buildTypes {
all {
productFlavors {
all {
ndk {
if (cFlags == null) { cFlags = "" }
cFlags = cFlags + " -DTEST="+dTest+" "
}
}
}
}
debug {
minifyEnabled false
ndk {
if (cFlags == null) { cFlags = "" }
cFlags = cFlags + " -DLOGGING=1 "
}
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk {
if (cFlags == null) { cFlags = "" }
cFlags = cFlags + " -DLOGGING=0 "
}
}
}
Здесь полный файл:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultPublishConfig "flavorARelease"
publishNonDefault true
defaultConfig {
minSdkVersion 15
targetSdkVersion 17
ndk {
moduleName "dTest"
ldLibs "log"
}
}
productFlavors.all {
ext.dTest = null
}
productFlavors {
flavorA {
dTest = 1
}
flavorB {
dTest = 2
}
}
buildTypes {
all {
productFlavors {
all {
ndk {
if (cFlags == null) { cFlags = "" }
cFlags = cFlags + " -DTEST="+dTest+" "
}
}
}
}
debug {
minifyEnabled false
ndk {
if (cFlags == null) { cFlags = "" }
cFlags = cFlags + " -DLOGGING=1 "
}
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk {
if (cFlags == null) { cFlags = "" }
cFlags = cFlags + " -DLOGGING=0 "
}
}
}
}