AndroidStudio多渠道打包

时间:2021-12-03 13:30:35

转自 http://blog.csdn.net/mynameishuangshuai/article/details/51783303

友盟统计用到了渠道ID
AndroidManifest.xml中添加

<application>
<meta-data
android:name="UMENG_CHANNEL"
android:value="${UMENG_CHANNEL_VALUE}" />

</application>

app/build.gradle中加入以下代码

android{
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def today = new Date().format('yyMMdd')
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// 输出apk名称为appname_v1.0_xiaomi.apk
def fileName = "appname_v${defaultConfig.versionName}_${variant.productFlavors[0].name}_${today}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
productFlavors {
yingyongbao {}
qh360 {}
baidu {}
xiaomi {}
huawei {}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
}

最后Sync一下gradle,build后,在app\build\outputs\apk路径下就能看到多个apk文件。