How to change the generated filename for App Bundles with Gradle?

前端 未结 6 1962
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 07:47

So to change the generated APK filename inside gradle android I could do something like:

applicationVariants.output.all {
    outputFileName = \"the_file_nam         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 08:19

    Solution from @SaXXuM works great! Task is not necessary for renaming artifact. You can call setProperty() directly in the android {} block. I prefer to have in the file name:

    • app id
    • module name
    • version name
    • version code
    • date
    • build type

    This is how I use it in my projects:

    build.gradle:

    apply from: "../utils.gradle"
    
    android {
        ...
        setProperty("archivesBaseName", getArtifactName(defaultConfig))
    }
    

    utils.gradle:

    ext.getArtifactName = {
        defaultConfig ->
            def date = new Date().format("yyyyMMdd")
            return defaultConfig.applicationId + "-" + project.name + "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + "-" + date
    }
    

    The result is: com.example-app-1.2.0-10200000-20191206-release.aab

    It works for both - APK and AAB.

提交回复
热议问题