如何更改Android App Bundles名称(app.aab)以反映App版本和构建类型 [英] How To change Android App Bundles name (app.aab) to reflect App version and build type

查看:883
本文介绍了如何更改Android App Bundles名称(app.aab)以反映App版本和构建类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建APK的同时,我可以在 build.gradle 脚本中更改APK名称,如下所示:

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"
      }
  }
}

我将拥有这样的 com.myapp.package-v1.x.x-release

是否可以使用Android App Bundles做类似的事情,总是有 app.aab

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

推荐答案

我已经提出了如何使用Gradle实现此目的的解决方案.

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

首先,我们必须在App build.gradle 文件中创建一个Gradle任务,该任务将在复制时重命名原始的 app.aab .此处对此方法进行了说明.为了方便起见,我们将添加另一种方法,该方法将删除旧的 app.aab 文件.

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"
    }
}

在此示例中,输出文件名将类似于 1.5.11.aab 然后,我们可以将这些任务组合到 publishRelease 任务中,该任务将用于发布App:

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']
}

这篇关于如何更改Android App Bundles名称(app.aab)以反映App版本和构建类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆