在gradle3.2.0以前,重命名apk打包名称使用defaultConfig.versionCode或者defaultConfig.versionName写法,如下所示:
//输出的为渠道包的名字,例如 xiaomi.apk
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outFile = output.outputFile
if (outFile != null && outFile.name.endsWith(".apk")) {
def fileName = "中国蓝_${defaultConfig.versionCode}_${defaultConfig.versionName}}.apk"
output.outputFile = new File(outFile.parent, fileName)
}
}
}
而在gradle3.2.0之后,再使用以前的写法的话,项目构建时则会有如下提示:
WARNING: API 'variantOutput.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'. It will be removed at the end of 2019. For more information, see?https://d.android.com/r/tools/task-configuration-avoidance. To determine what is calling variantOutput.getPackageApplication(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace. Affected Modules: app
需将defaultConfig替换为variant,以下为修改后的写法:
//输出的为渠道包的名字,例如 xiaomi.apk
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName="中国蓝_${variant.versionCode}_${variant.versionName}}.apk"
}
}
|