How To change Android App Bundles name (app.aab) to reflect App version and build type

眉间皱痕 提交于 2021-02-16 16:43:28

问题


While I'm building an APK I can change APK name in build.gradle script, like that:

android.applicationVariants.all { variant ->
  if (variant.buildType.name != "debug") {
      variant.outputs.all {
          outputFileName = "${variant.applicationId}-v${variant.versionName}-${variant.name}.apk"
      }
  }
}

An I'll have something like this com.myapp.package-v1.x.x-release

Is there a way to do something similar with Android App Bundles, it is not convenient to always have app.aab


回答1:


I have come up with the solution of how to achieve this with Gradle.

First, we have to create in App build.gradle file a Gradle task that will rename the original app.aab on copy. This method is described here. Then for conveniance, we will add another method that will delete old app.aab file.

android{ 
.....
}
dependencies{
.....
}
.....

task renameBundle(type: Copy) {
    from "$buildDir/outputs/bundle/release"
    into "$buildDir/outputs/bundle/release"

    rename 'app.aab', "${android.defaultConfig.versionName}.aab"
}

task deleteOriginalBundleFile(type: Delete) {
    delete fileTree("$buildDir/outputs/bundle/release").matching {
        include "app.aab"
    }
}

In this example the output file name will be something like 1.5.11.aab Then we can combine those tasks together into publishRelease task which will be used for publishing the App:

task publishRelease(type: GradleBuild) {
    tasks = ['clean', 'assembleRelease', 'bundleRelease', 'renameBundle', 'deleteOriginalBundleFile']
}


来源:https://stackoverflow.com/questions/54593789/how-to-change-android-app-bundles-name-app-aab-to-reflect-app-version-and-buil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!