当我使用 gradle 构建应用程序时,我想将“app-release.apk”文件名更改为如下所示。
[format] (appname of package name)_V(version code)_(yyMMdd)_(R|T) [explain] (appname of package name) : example) com.example.myApp -> myApp (version code) : build version code 2.2.3 -> 223 (yyMMdd) : build date 2015.11.18 -> 151118 (R|T) : if app is release, "R" but debug is "T".
如果我在 release 中生成一个 apk 文件,结果是:myApp_V223_151118_R.apk。
如何在gradle中制作这样的文件名?
最佳答案
这可能是最短的方法:
defaultConfig {
...
applicationId "com.blahblah.example"
versionCode 1
versionName "1.0"
setProperty("archivesBaseName", applicationId + "-v" + versionCode + "(" + versionName + ")")
}
buildType: 像这样
buildTypes {
debug {
...
versionNameSuffix "-T"
}
release {
...
versionNameSuffix "-R"
}
}
请记住,Android Studio 默认通过构建类型名称添加 versionNameSuffix,因此您可能不需要这个。
更新。在新版本的 Android Studio 中你可以写得更短一些(感谢 szx 评论):
defaultConfig {
...
archivesBaseName = "$applicationId-v$versionCode($versionName)"
}
关于android - 如何使用这种格式的 gradle 更改 apk 名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33775160/