如何使用Gradle更改App Bundle的生成文件名? [英] How to change the generated filename for App Bundles with Gradle?

查看:1360
本文介绍了如何使用Gradle更改App Bundle的生成文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此要在gradle android中更改生成的APK文件名,我可以执行以下操作:

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

applicationVariants.output.all {
    outputFileName = "the_file_name_that_i_want.apk"
}

是否有类似的东西生成的App Bundle文件?如何更改生成的App Bundle文件名?

Is there a similar thing for the generated App Bundle file? How can I change the generated App Bundle filename?

推荐答案

作为马丁·齐特勒斯回答,以下内容将侦听添加的任务,然后为任何 bundle * 任务插入重命名任务

As a more generic way to Martin Zeitlers answer the following will listen for added tasks, then insert rename tasks for any bundle* task that gets added.

只需将其添加到 build.gradle 文件的底部即可。

Just add it to the bottom of your build.gradle file.


注意:它将添加不必要的任务,但是由于这些任务与任何文件夹都不匹配,因此将跳过这些任务。例如> Task:app:renameBundleDevelopmentDebugResourcesAab NO-SOURCE



tasks.whenTaskAdded { task ->
    if (task.name.startsWith("bundle")) {
        def renameTaskName = "rename${task.name.capitalize()}Aab"
        def flavor = task.name.substring("bundle".length()).uncapitalize()
        tasks.create(renameTaskName, Copy) {
            def path = "${buildDir}/outputs/bundle/${flavor}/"
            from(path)
            include "app.aab"
            destinationDir file("${buildDir}/outputs/renamedBundle/")
            rename "app.aab", "${flavor}.aab"
        }

        task.finalizedBy(renameTaskName)
    }
}

这篇关于如何使用Gradle更改App Bundle的生成文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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