[Flutter generate default apk in flutter-apk how to rename those file like I did in build.gradle]

338 Views Asked by At

Hi guys my question is simple, I am able to modify the output file name for android.

Basically, there will be two folders, named apk and flutter-apk.

For example, my productFlavors got 3 and buildType got 2 (release and debug).

If I run flutter run --flavor production --release

I will get my Android build.gradle generated file in : build/app/outputs/apk/production/release/

This filename.apk I can customise it using below :

    applicationVariants.all { variant ->
        variant.outputs.each { output -> }}

However, here come my question, location in build/app/outputs/flutter-apk will create a file at the same time. The naming is using flavorDimensions in build.gradle + dash + productFlavor + dash + buildType + .apk

How can I rename it, I want it to be the same as my apk folder.

Also, is there any way I can disable it so that my flutter-apk folder won't generate the same apk file as I mention above location. They are actually same apk files but generating twice. I just want build/app/outputs/apk to output my APK/appbundle.

I know I can run flutter clean to delete build folder, is there any efficient way I can always do ( a script to delete build folder first and start build apk for either APK or flutter-apk folder) Can i enable or disable choose the output path between apk or flutter-apk folder ? Or by default both folder will generate apk files and we cannot disable it ?

1

There are 1 best solutions below

0
velval On

This is how I rename the APK file. Change your android build.gradle like below:

android {
   ...
   project.ext.set("appName", "my-app-name")
   ...
   defaultConfig {
       ... 
       setProperty("archivesBaseName", "$appName-$versionName-$versionCode")
    }
}

Note the resulted build file will be located under: \build\app\outputs\apk\release instead of \build\app\outputs\flutter-apk