在 Android Studio 中使用自定义名称格式构建发布 apk [英] Build release apk with customize name format in Android Studio
本文介绍了在 Android Studio 中使用自定义名称格式构建发布 apk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望使用以下名称格式(带时间戳)构建 .apk
.
I want the .apk
to be built with the following name format (with timestamp).
如何设置?
格式:{app_name}{yyyymmddhis}.apk
现在,它被固定为名称 {app_name}-{release}.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 Studio 1.0 进行编辑 ======
====== EDIT with Android Studio 1.0 ======
如果你使用的是 Android Studio 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
部分更改为:
You should change the build.Types
part to this:
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 Studio 中使用自定义名称格式构建发布 apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文