我想将test
每个风味设置不同的变量作为定义传递给 NDK。但由于某种原因,他总是传递最后一种味道的价值。
这是 build.gradle:
apply plugin: 'com.android.library'
def test
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultPublishConfig "flavorARelease"
publishNonDefault true
defaultConfig {
minSdkVersion 15
targetSdkVersion 17
ndk {
moduleName "test"
ldLibs "log"
}
}
productFlavors {
flavorA {
test = 1
}
flavorB {
test = 2
}
}
buildTypes {
debug {
ndk {
if (cFlags == null) { cFlags = "" }
cFlags = cFlags + " -DLOGGING=1 -DTEST="+test+" "
}
minifyEnabled false
}
release {
ndk {
if (cFlags == null) { cFlags = "" }
cFlags = cFlags + " -DLOGGING=0 -DTEST="+test+" "
}
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
这是生成的 Android.mk 中的 CFLAG 行
构建/中间体/ndk/flavorA/debug/Android.mk:
LOCAL_CFLAGS := -DLOGGING=1 -DTEST=2
我期待-DTEST=1
这里
构建/中间体/ndk/flavorB/debug/Android.mk:
LOCAL_CFLAGS := -DLOGGING=1 -DTEST=2
那么我的错误在哪里?或者我怎样才能实现我的目标?还请考虑真正的问题更复杂,如果可能的话,我想在“buildTypes”部分中进行这些定义。