Android Studio系列教程六–Gradle多渠道打包
<meta-data
android:name="UMENG_CHANNEL"
android:value="${UMENG_CHANNEL_VALUE}" />
android {
...
defaultConfig {
...
manifestPlaceholders = [ UMENG_CHANNEL_VALUE:"default_channel" ]
}
}
android {
...
defaultConfig {
...
manifestPlaceholders = [ UMENG_CHANNEL_VALUE:"default_channel" ]
}
productFlavors {
default_channel{}
wandoujia{}
_360{}
yingyongbao{}
xiaomi{}
baidu{}
huawei{}
jifeng{}
}
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [ UMENG_CHANNEL_VALUE:name ]
}
}
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith(‘.apk‘)) {
File outputDirectory = new File(outputFile.parent);
def fileName
if (variant.buildType.name == "release") {
// fileName = "app_v${defaultConfig.versionName}_${packageTime()}_${variant.productFlavors[0].name}.apk"
fileName = "caixiangji_${variant.productFlavors[0].name}.apk"
} else {
// fileName = "app_v${defaultConfig.versionName}_${packageTime()}_beta.apk"
fileName = "caixiangji_${variant.productFlavors[0].name}_beta.apk"
}
output.outputFile = new File(outputDirectory, fileName)
}
}
}
//在Android studio下的Terminal输入
gradlew assembleWandoujiaRelease
打开AndroidStudio的Gradle tasks面板
Android高阶之Android studio友盟多渠道打包方式
原文:http://www.cnblogs.com/chenxibobo/p/6434847.html