这是一个具有三种口味的简单 gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.apipas.app.listallflavor"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
au {
applicationId 'com.apipas.app.listallflavor.au'
resConfigs 'en-rAU'
}
es {
applicationId 'com.apipas.app.listallflavor.es'
resConfigs 'es'
}
de {
applicationId 'com.apipas.app.listallflavor.de'
resConfigs 'de'
}
}
productFlavors.all {
flavor ->
println( flavor.name)
buildConfigField 'String', 'var_'+flavor.name, '\"'+flavor.name+'\"'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
BuildConfig.java 是:
/**
* Automatically generated file. DO NOT MODIFY
*/
package com.apipas.app.listallflavor;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.apipas.app.listallflavor.au";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "au";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
// Fields from product flavor: au
public static final String var_au = "au";
}
我的期望:
/**
* Automatically generated file. DO NOT MODIFY
*/
package com.apipas.app.listallflavor;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.apipas.app.listallflavor.au";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "au";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
// Fields from product flavor: au
public static final String var_au = "au";
public static final String var_de = "de";
public static final String var_es = "es";
}
奇怪的事情,我可以在日志中看到所有口味:au de es
但我没有像我预期的那样在 buildConfig 中为 'de' 和 'es' 提供字段.. 有什么提示吗,伙计们?