How to change the generated filename for App Bundles with Gradle?

前端 未结 6 1963
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 07:47

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

applicationVariants.output.all {
    outputFileName = \"the_file_nam         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 08:07

    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.

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

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

提交回复
热议问题