Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] build.gradle – How to disable default gradle buildType suffix (-release, -debug)

Posted on November 11, 2022 By

Solution 1 :

I realzed that I have to create custom tasks after reading other questions and answers:
How to change the generated filename for App Bundles with Gradle?

Renaming applicationVariants.outputs’ outputFileName does not work because those are for .apks.

I’m using Gradle 5.4.1 so my Copy task syntax reference is here.

I don’t quite understand where the “app.aab” name string came from, so I defined my own aabFile name string to match my toolchain’s output.

I don’t care about the source file so it’s not deleted by another delete task.

Also my toolchain seems to be removing unknown variables surrounded by “${}” so I had to work around ${buildDir} and ${flavor} by omitting the brackets and using concatenation for proper delimiting.

    tasks.whenTaskAdded { task ->
    if (task.name.startsWith("bundle")) { // e.g: buildRelease
        def renameTaskName = "rename${task.name.capitalize()}Aab" // renameBundleReleaseAab
        def flavorSuffix = task.name.substring("bundle".length()).uncapitalize() // "release"
        tasks.create(renameTaskName, Copy) {
            def path = "$buildDir/outputs/bundle/" + "$flavorSuffix/"
            def aabFile = "${android.defaultConfig.applicationId}-" + "$flavorSuffix" + ".aab"
            from(path) {
                include aabFile
                rename aabFile, "${android.defaultConfig.applicationId}.aab"
            }
            into path
        }

        task.finalizedBy(renameTaskName)
    }
}

As the original answer said: This will add more tasks than necessary, but those tasks will be skipped since they don’t match any folder.
e.g.

Task :app:renameBundleReleaseResourcesAab NO-SOURCE

Problem :

I migrated a 3rd-party tool’s gradle.build configs, so it uses android gradle plugin 3.5.3 and gradle 5.4.1.

The build goes all smoothly, but when I’m trying to make an .aab archive, things got broken because the toolchain expects the output .aab file to be named MyApplicationId.aab, but the new gradle defaults to output MyApplicationId-release.aab, with the buildType suffix which wasn’t there.

I tried to search for a solution, but documentations about product flavors are mostly about adding suffix. How do I prevent the default “-release” suffix to be added? There wasn’t any product flavor blocks in the toolchain’s gradle config files.

READ  [FIXED] android - Cannot complete build gradle with dialogflow
Powered by Inline Related Posts
Android Tags:android-gradle-plugin, android-productflavors, build.gradle

Post navigation

Previous Post: [FIXED] android – Build not succed in flutter
Next Post: [FIXED] kotlin – Opening the application from the results google.com, always directs to the home page of WebView Android

Related Posts

[FIXED] java – How to perform some processing on a livedata before returning it Android
[FIXED] android – Extracting frame from video from storage device using MediaMetadataRetriever – IllegalArgumentException at setDataSource() Android
[FIXED] java – How to show only one AR object at a time on Achor? Android
[FIXED] Android Volley Array in JSON Android
[FIXED] java – Unable to run app in emulator with API 29 android studio Android
[FIXED] Which HTML tags are supported by the Android HTML class and how do I use HtmlCompat? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What color are dead flea eggs?
  • What is Indiana vine?
  • What’s the downside of a Chromebook?
  • Is phosphide the same as phosphorus?
  • Why do you need an S bend?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme