Pau*_*est 9 android gradle android-gradle-plugin
如何在Gradle Android输出文件名中添加日期/时间戳?
应该像project_v0.5.0_201503110212_public.apk
已经看过了
Fre*_*red 15
我假设你想要它以你指定的格式,所以这是一个可能的解决方案.
在gradle文件中,您可以定义一个新函数来获取您想要的日期时间字符串:
import java.text.DateFormat
import java.text.SimpleDateFormat
def getDateTime() {
DateFormat df = new SimpleDateFormat("yyyyMMddHHmm");
return df.format(new Date());
}
Run Code Online (Sandbox Code Playgroud)
然后对于所有变体,您只需运行此:
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"))
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,这并不像您发布的那样真正输出apk名称,但我想这足以帮助您.
这段代码对我有用。
applicationVariants.all { variant ->
variant.outputs.each { output ->
def project = "Your App Name"
def SEP = "_"
def flavor = variant.productFlavors[0].name
def buildType = variant.variantData.variantConfiguration.buildType.name
def version = variant.versionName
def date = new Date();
def formattedDate = date.format('ddMMyy_HHmm')
def newApkName = project + SEP + flavor + SEP + buildType + SEP + version + SEP + formattedDate + ".apk"
output.outputFile = new File(output.outputFile.parent, newApkName)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5521 次 |
| 最近记录: |