Android Studio多渠道打包主要是配置app moudle里的build.gradle文件:
android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
}
}
signingConfigs {
debug {
storeFile file("../debug.keystore")
}
release {
storeFile file("../release.keystore")
storePassword "***"
keyAlias "***"
keyPassword "***"
}
}
//打包渠道
productFlavors {
default_channel {}
baidu {}
yingyongbao {}
_360 {}
xiaomi {}
huawei {}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
//def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
//配置生成的apk名为app_v***(版本号)_***(渠道名).apk
def fileName = "app_v${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}