apk打包签名重命名

在AS中通过


apk打包签名重命名_第1张图片

这种方式打包签名的apk名称总是release.apk和debug.apk,着实不是很方便。

重命名apk打包之后的名称

打开app/build.gradle文件
1.添加与android{}同一级别的内容,如下:

def renameAPK(variant, defaultConfig) {
    variant.outputs.each { output ->
        def applicationName = 'test'
        def formattedDate = new Date().format('yyyyMMdd')
        def file = output.packageApplication.outputFile
        def fileName
        if (variant.buildType.name.equals('release')) {
            fileName = applicationName + "_v" + defaultConfig.versionName + "-" + formattedDate + ".apk"
        }
        if (variant.buildType.name.equals('debug')) {
            fileName = applicationName + "_v" + defaultConfig.versionName + "-" + formattedDate + "-debug.apk"
        }
        output.packageApplication.outputFile = new File(file.parent, fileName)
    }
}

2.在android{}里添加如下代码:

 android.applicationVariants.all { variant ->
        renameAPK(variant, defaultConfig)
    }

这样不但可以重命名apk的名称,还可以在名称上面加入版本信息和打包时间,一目了然。

你可能感兴趣的:(apk打包签名重命名)