动态修改AAR名字
android.libraryVariants.all { variant ->
if(variant.name.equalsIgnoreCase("release")) {
variant.outputs.all { output ->
def f = output.outputFileName
if (f != null && f.endsWith('.aar')) {
def fileName = "zidingyi-v${defaultConfig.versionName}.aar"
output.outputFileName = fileName
}
}
}
}
动态修改APK名字
applicationVariants.all { variant ->
variant.outputs.all { output ->
def versionName = variant.versionName
def versionCode = variant.versionCode
def buildType = variant.buildType.name
if (variant.buildType.name == 'debug') {
outputFileName = "${project.name}_${variant.flavorName}_v${versionName}_c${versionCode}_${buildType}.apk"
} else {
outputFileName = "${project.name}_${variant.flavorName}_v${versionName}_${buildTime()}_${buildType}.apk"
}
}
}
// 打包时间
static def buildTime() {
return new Date().format("yyyyMMddHHmm", TimeZone.getTimeZone("GMT+08:00"))
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
def versionName = variant.versionName
def buildType = variant.buildType.name
//下面的路径:${buildDir}/intermediates/manifests/full/${variant.dirName}/AndroidManifest.xml
def xmlFile = project.file("${project.getProjectDir()}/src/main/AndroidManifest.xml")
def rootManifest = new XmlSlurper().parse(xmlFile)
def application = rootManifest.getProperty("application")
def productName = application['@android:label']
def flavorName = variant.flavorName
if (variant.buildType.name == 'debug') {
outputFileName = "${productName}_v${versionName}_${buildType}.apk"
} else {
outputFileName = "${productName}_v${versionName}_${buildType}_${buildTime()}.apk"
}
}
}