如何在Gradle
Android输出文件名中添加日期/时间戳?
应该像project_v0.5.0_201503110212_public.apk
已经看过了
> how append date build to versionNameSuffix on gradle
> How to pass arguments from command line to gradle
解决方法
我假设你想要它以你指定的格式,所以这是一个可能的解决方案.
在您的gradle文件中,您可以定义一个新函数来获取您想要的日期时间字符串:
import java.text.DateFormat
import java.text.SimpleDateFormat
def getDateTime() {
DateFormat df = new SimpleDateFormat("yyyyMMddHHmm");
return df.format(new Date());
}
然后对于所有变体,您只需运行此:
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"))
}
}
}
}
请注意,这并不像您发布的那样输出apk名称,但我想这足以帮助您.