如何使用 Gradle 更改 App Bundle 的生成文件名?

How to change the generated filename for App Bundles with Gradle?(如何使用 Gradle 更改 App Bundle 的生成文件名?)
本文介绍了如何使用 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 NO-SOURCE

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 的生成文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)