Android:添加日期/时间到gradle输出apk文件名 [英] Android: add date/time to gradle output apk filename

查看:372
本文介绍了Android:添加日期/时间到gradle输出apk文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



应该像project_v0.5.0_201503110212_public.apk


$

如何为Gradle Android输出文件名添加日期/时间戳? b $ b

已经看过


解决方案

我假设您希望使用您指定的格式,所以这里有一个可能的解决方案。



在您的gradle文件中,您可以定义一个新函数来获取您想要的日期时间字符串:

  import java.text.DateFormat 
import java.text.SimpleDateFormat
$ b $ get getDateTime(){
DateFormat df = new SimpleDateFormat(YYYYMMDDHHmm );

return df.format(new Date());
}

然后对于所有变体,您可以简单地运行它:

  android {
// ...
buildTypes {
// ...
android。 applicationVariants.all {variant - >
variant.outputs.each {输出 - >
def file = output.outputFile
output.outputFile = new File(file.parent,file.name.replace(。apk, - + getDateTime()+.apk))
}
}
}
}

这并不是真的输出你发布的apk名字,但我想这足以帮助你。


How to add date/time stamp to Gradle Android output file name?

Should be like project_v0.5.0_201503110212_public.apk

Already looked at

解决方案

I'm assuming that you want it in the format you specified, so here's one possible solution.

In your gradle file you can define a new function to get the date time string like you desire:

import java.text.DateFormat
import java.text.SimpleDateFormat

def getDateTime() {
    DateFormat df = new SimpleDateFormat("YYYYMMDDHHmm");

    return df.format(new Date());
}

Then for all variants you can simply run this:

android {
    //...
  buildTypes {
    //...
    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def file = output.outputFile
            output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + getDateTime() + ".apk"))
        }
    }
  }
}

Note that this doesn't really output the apk name like you posted, but I guess it's enough to help you out.

这篇关于Android:添加日期/时间到gradle输出apk文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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