建立在Android的工作室自定义名称格式的发行APK [英] Build release apk with customize name format in Android Studio

查看:120
本文介绍了建立在Android的工作室自定义名称格式的发行APK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的 .apk文件将具有以下名称格式(带时间戳)建成。

I want the .apk to be built with the following name format (with timestamp).

我如何设置呢?

格式为: {APP_NAME} {} yyyymmddhis .apk文件

现在,它是固定的名称 {APP_NAME} - {}发布.apk文件

Now, it is fixed with the name {app_name}-{release}.apk

推荐答案

build.gradle 文件,你应该改变/添加 buildTypes 是这样的:

in the build.gradle file, you should change/add buildTypes like this:

buildTypes {
      release {
        signingConfig signingConfigs.release
        applicationVariants.all { variant ->
            def file = variant.outputFile
            def date = new Date();
            def formattedDate = date.format('yyyyMMddHHmmss')
            variant.outputFile = new File(
                                    file.parent, 
                                    file.name.replace("-release", "-" + formattedDate)
                                    )
        }
    }       
}


======编辑与Android工作室1.0 ==


====== EDIT with Android Studio 1.0 ======

如果您使用的是Android的工作室1.0,你会得到一个错误这样的:

If you are using Android Studio 1.0, you will get an error like this:

Error:(78, 0) Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@67e7625f.

您应该 build.Types 部分改成这样:

buildTypes {
        release {
            signingConfig signingConfigs.releaseConfig
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def date = new Date();
                    def formattedDate = date.format('yyyyMMddHHmmss')
                    output.outputFile = new File(output.outputFile.parent, 
                                            output.outputFile.name.replace("-release", "-" + formattedDate)
                                            )
                }
            }
        }
    }

这篇关于建立在Android的工作室自定义名称格式的发行APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆