Android aar build.gradle重新命名打包

重命名apk

buildTypes {
        release {
            minifyEnabled false  // 混淆
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def fileName = "chaolong_V${defaultConfig.versionName}_${buildType.name}_${releaseTime()}.apk"
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        output.outputFile = new File(outputFile.parent, fileName)
                    }
                }
            }
            signingConfig signingConfigs.config
        }

重命名library

android.libraryVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith("release.aar")) {
                def fileName = "XXX-${defaultConfig.versionName}.aar"
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }


获取时间

def releaseTime() {
    return new Date().format("yyyyMMdd", TimeZone.getTimeZone("GMT+08"))
}
;