完美处理 Android App 的 apk 输出路径与文件名

实现代码

复制代码
buildTypes {

        // ...
    
        
        applicationVariants.all {
            variant ->
                variant.outputs.all {
                    Calendar calendar = Calendar.getInstance(Locale.CHINA);
                    def buildDate = String.format(Locale.CHINA, "%04d%02d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH))
                    def versionName = variant.versionName
                    def versionCode = variant.versionCode
                    //项目名-版本名-版本号-release/debug.apk
                    if (variant.buildType.name.equals('release')) {
                        variant.getPackageApplication().outputDirectory = new File("ApkOutputs/release")
                        outputFileName = "${rootProject.getName()}-v${versionName}-${versionCode}-${buildDate}-release.apk"
                    } else {
                        variant.getPackageApplication().outputDirectory = new File("ApkOutputs/debug")
                        outputFileName = "${rootProject.getName()}-v${versionName}-${versionCode}-${buildDate}-debug.apk"
                    }
                }
        }
    }

效果

相关推荐
辰风沐阳1 小时前
nvm - node 版本管理工具【macOS/Linux】
linux·运维·macos
StackNoOverflow2 小时前
MySQL Explain 返回列详解:从入门到实战,附 SQL 与避坑大全
android
恋恋风尘hhh2 小时前
滑动验证码前端安全研究:以顶象(dingxiang-inc)为例
前端·安全
君穆南8 小时前
基于 NFS 与 Rsync 实现跨服务器 Seafile 数据平滑迁移实战
linux·运维·git
bloglin999998 小时前
scp、rsync远程文件同步
linux·运维·服务器
迦南的迦 亚索的索8 小时前
LINUX环境
linux·运维·服务器
yuanjj888 小时前
linux下调试域格CLM920 NC5等9x07平台模块 QMI拨号
linux·运维·服务器
懂懂tty9 小时前
React状态更新流程
前端·react.js
IMPYLH9 小时前
Linux 的 printenv 命令
linux·运维·服务器·bash
SilentSamsara9 小时前
SSH 远程管理:密钥登录 + 隧道转发,一次性配置好
linux·运维·服务器·ubuntu·centos·ssh