Android Studio修改apk打包生成名称

在app的build.gradle文件的android{}括号里添加

android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {             
                //在这里修改apk文件名
                def fileName = "想要的文件名.apk"
                output.outputFile = new File(outputFile.parent, fileName)               
            }
        }
}

gradle 3.0以上版本改用以下代码添加

android.applicationVariants.all {
    variant ->
        variant.outputs.all {
            //在这里修改apk文件名
            outputFileName = "${variant.name}-v${variant.versionName}.apk"
        }
}

variant.name软件名称,variant.versionName软件版本号,比如你的软件叫jianshu,版本号为1.0.0,则输出的软件名称就是 jianshu-v1.0.0.apk

可通过以下途径关注本人:

个人网站https://zachary46.xyz

Githubhttps://github.com/Zachary46

CSDN博客https://blog.csdn.net/Zachary_46

博客园https://www.cnblogs.com/Zachary46

掘金https://juejin.im/user/5b57e9a16fb9a04f8e1432ef

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容