如何使用gradle这样的格式更改apk名称?

2024-05-16

当我使用 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".
  

如果我在发布中生成 apk 文件,结果为:myApp_V223_151118_R.apk。

如何在gradle中创建这样的文件名?


这可能是最短的方法:

defaultConfig {
    ...
    applicationId "com.blahblah.example"
    versionCode 1
    versionName "1.0"
    setProperty("archivesBaseName", applicationId + "-v" + versionCode + "(" + versionName + ")")
}

构建类型:像这样

buildTypes {
    debug {
        ...
        versionNameSuffix "-T"
    }
    release {
        ...
        versionNameSuffix "-R"
    }
}

请记住,Android Studio 默认情况下通过构建类型名称添加 versionNameSuffix,因此您可能不需要它。

更新。在新版本的 Android Studio 中,你可以把它写得短一些(感谢szx https://stackoverflow.com/users/249230/szx评论):

defaultConfig {
    ...
    archivesBaseName = "$applicationId-v$versionCode($versionName)"
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用gradle这样的格式更改apk名称? 的相关文章

随机推荐