完美处理 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"
                    }
                }
        }
    }

效果

相关推荐
Vect__6 小时前
深刻理解进程、线程、程序
linux
kyriewen116 小时前
你点的“刷新”是假刷新?前端路由的瞒天过海术
开发语言·前端·javascript·ecmascript·html5
末日汐7 小时前
传输层协议UDP
linux·网络·udp
skywalk81638 小时前
Kotti Next的tinyfrontend前端模仿Kotti 首页布局还是不太好看,感觉比Kotti差一点
前端
zzzsde10 小时前
【Linux】库的制作和使用(3)ELF&&动态链接
linux·运维·服务器
CQU_JIAKE10 小时前
4.3【A]
linux·运维·服务器
RopenYuan10 小时前
FastAPI -API Router的应用
前端·网络·python
qing2222222210 小时前
Linux中修改mysql数据表
linux·运维·mysql
Alvin千里无风10 小时前
在 Ubuntu 上从源码安装 Nanobot:轻量级 AI 助手完整指南
linux·人工智能·ubuntu