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

查看:37
本文介绍了如何使用 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?

推荐答案

作为一种更通用的方式来Martin Zeitlers 的回答以下将侦听添加的任务,然后为添加的任何 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.

注意:它会添加比需要更多的任务,但这些任务将被跳过,因为它们不匹配任何文件夹.例如<代码>>任务 :app:renameBundleDevelopmentDebugResourcesAab 无源

Note: It will add more tasks than necessary, but those tasks will be skipped since they don't match any folder. e.g. > 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天全站免登陆