How to change apk name by using gradle like this format?

后端 未结 3 620
死守一世寂寞
死守一世寂寞 2021-01-30 05:07

I\'d like to change \"app-release.apk\" file name to like following when I build an app by using gradle.

[format]
(appname of package name)_V(version code)_(yyMMdd)_(         


        
3条回答
  •  [愿得一人]
    2021-01-30 05:52

    This may be the shortest way:

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

    buildType: like so

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

    Keep in mind, Android Studio adds versionNameSuffix by build type name by default, so you may not need this.

    Upd. In new versions of Android Studio you can it write little shorter(thanks for szx comment):

    defaultConfig {
        ...
        archivesBaseName = "$applicationId-v$versionCode($versionName)"
    }
    

提交回复
热议问题