Android:添加日期/时间到gradle输出apk文件名 [英] Android: add date/time to gradle output apk filename
问题描述
应该像project_v0.5.0_201503110212_public.apk
$
如何为Gradle Android输出文件名添加日期/时间戳? b $ b
已经看过
- 附加日期构建到gradle上的versionNameSuffix / questions / 11696521 / how-to-pass-arguments-from-command-line-to-gradle>如何将参数从命令行传递给gradle
我假设您希望使用您指定的格式,所以这里有一个可能的解决方案。
在您的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
- how append date build to versionNameSuffix on gradle
- How to pass arguments from command line to gradle
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屋!