208

Whenever I generate a signed apk in Android Studio, by default it gives the name as app-release.apk...

Can we do any settings so that it should prompt and ask me the name which need to be assigned to the apk(the way it do in eclipse)

What I do is - rename the apk after it generated. This doesn't give any errors but is there any genuine way so that i can do any changes in settings to get a prompt.

Note::

while generating apk android studio is giving me a prompt to select the location(only)enter image description here

Prabs
  • 4,923
  • 6
  • 38
  • 59
  • 1.change build varient to release 2.select build->generate signed apk from menu bar. In this way am generating signed apk – Prabs Jan 31 '15 at 07:08
  • All the answers here are not correct.. This issue will still occur using any of them... The problem is studio caching the name of the apk artifact, and keep using the cached name instead of using the new generated one! – TacB0sS Jan 09 '18 at 07:47

20 Answers20

161

Yes we can change that but with some more attention

SeeThis

Now add this in your build.gradle in your project while make sure you have checked the build variant of your project like release or Debug so here I have set my build variant as release but you may select as Debug as well.

    buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                signingConfig getSigningConfig()
                applicationVariants.all { variant ->
                    variant.outputs.each { output ->
                        def date = new Date();
                        def formattedDate = date.format('yyyyMMddHHmmss')
                        output.outputFile = new File(output.outputFile.parent,
                                output.outputFile.name.replace("-release", "-" + formattedDate)
    //for Debug use output.outputFile = new File(output.outputFile.parent,
   //                             output.outputFile.name.replace("-debug", "-" + formattedDate)
                        )
                    }
                }
            }
        }

You may Do it With different Approach Like this

 defaultConfig {
        applicationId "com.myapp.status"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        setProperty("archivesBaseName", "COMU-$versionName")
    }

Using Set property method in build.gradle and Don't forget to sync the gradle before running the projects Hope It will solve your problem :)

A New approach to handle this added recently by google update You may now rename your build according to flavor or Variant output //Below source is from developer android documentation For more details follow the above documentation link
Using the Variant API to manipulate variant outputs is broken with the new plugin. It still works for simple tasks, such as changing the APK name during build time, as shown below:

// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.
android.applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = "${variant.name}-${variant.versionName}.apk"
    }
}

Renaming .aab bundle This is nicely answered by David Medenjak

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)
    }
//@credit to David Medenjak for this block of code
}

Is there need of above code

What I have observed in the latest version of the android studio 3.3.1

The rename of .aab bundle is done by the previous code there don't require any task rename at all.

Hope it will help you guys. :)

dsf
  • 1,203
  • 1
  • 6
  • 11
Abhishek Chaubey
  • 2,960
  • 1
  • 17
  • 24
  • so use the string there in the like "Abhishek Chaubey" instaed of formattedDate – Abhishek Chaubey Jan 31 '15 at 10:59
  • Is it possible to add `versionName` somehow? – zygimantus Oct 02 '16 at 12:13
  • @AbhishekChaubey I'm not able to run the code through Android Studio anymore after changing the apk name, any idea? please help...it shows `The APK file /Users/.../outputs/apk/NewName-debug-20161004172815.apk does not exist on disk.` – Beeing Jk Oct 04 '16 at 09:32
  • @BeeingJk rebuild the project or once close the android studio and delete output folder from the build directory and then rebuild the project or try it by cleaning .hope it may help you – Abhishek Chaubey Oct 05 '16 at 10:53
  • @AbhishekChaubey I am also facing the same issue. As you said, I cleaned the code, deleted build folders, restarted studio. Still not getting – Nigam Patro Jul 24 '17 at 05:51
  • @NigamPatro is there any log you are getting after applying the above solution,please elaborate your problem – Abhishek Chaubey Jul 24 '17 at 05:58
  • As @BeeingJk mentioned the issue. I am also facing the issue. – Nigam Patro Jul 26 '17 at 13:19
  • 5
    As of Android Studio 3.0 output.outputFile is read only. @johnny-doe's [answer](https://stackoverflow.com/questions/28249036/app-release-apk-how-to-change-this-default-generated-apk-name#46028128) is the new solution. – krishh Oct 07 '17 at 08:43
  • This will not solve the issue.. the problem is the studio caching the first output name, and not updating it to the new one – TacB0sS Jan 09 '18 at 07:49
  • How we can add architectures name to apk name? For exampe "MyApp_V223_151118_R_arm.apk" and "MyApp_V223_151118_R_x86.apk" – b24 Feb 15 '18 at 06:59
  • give this Cannot set the value of read-only property 'outputFile' for – Radesh Aug 05 '18 at 08:23
  • the last hint worked fine for me, gradle version 3.2.1 – Arthur Melo Nov 03 '18 at 18:20
  • Anyone know how set the app bundle name in similar fashion as it still taking app.aab as name by default even after following above mentioned steps. – shaby Feb 18 '19 at 11:03
  • @shaby i have updated the code for your question. it is very late but hope it will help you – Abhishek Chaubey Feb 22 '19 at 06:30
  • Please where can I locate these config files? Thanks @AbhishekChaubey – Vixson Jun 18 '20 at 08:36
  • If you@Vixson mean where you put this code then it will be in your app build.gradle file write the code inside your android{ } tag – Abhishek Chaubey Jun 18 '20 at 15:05
  • setProperty("archivesBaseName", "COMU-$versionName") did the trick for me, thanks @AbhishekChaubey – Iftikar Urrhman Khan Jun 27 '20 at 09:13
97

You might get the error with the latest android gradle plugin (3.0):

Cannot set the value of read-only property 'outputFile'

According to the migration guide, we should use the following approach now:

applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = "${applicationName}_${variant.buildType.name}_${defaultConfig.versionName}.apk"
    }
}

Note 2 main changes here:

  1. all is used now instead of each to iterate over the variant outputs.
  2. outputFileName property is used instead of mutating a file reference.
Johnny Doe
  • 3,280
  • 4
  • 29
  • 45
  • 1
    Now this is the correct answer of October 2017 for Android Studio 3.0 Beta 7. Thanks. – krishh Oct 05 '17 at 17:38
  • 7
    In my case `${applicationName}` resolved to `BuildType_Decorated{name=applicationName, debuggable=false, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscript...` (shortnened for clarity). This caused packaging to fail. For me `${applicationId}` or `${archivesBaseName}` were better options. Also `${defaultConfig.versionName}` for me is null. So `${applicationId}_${variant.name}-${variant.versionName}` is what I ended up with. – pcdev Dec 29 '17 at 02:19
  • Not quite sure how to resolve this (appears in **Gradle Messages** when syncing *(Gradle v4.4)* `No signature of method: java.util.ArrayList.all() is applicable for argument types: (build_8pov2vcee3orzmdxelrhjbbwu$_run_closure2$_closure6$_closure12$_closure13) values: [build_8pov2vcee3orzmdxelrhjbbwu$_run_closure2$_closure6$_closure12$_closure13@296351f6] Possible solutions: tail(), any(), tail(), last(), last(), add(java.lang.Object)` I added this to `defaultConfig{}` block and to `buildTypes {release{}}` block, both giving the same error – CybeX Jan 18 '18 at 10:40
  • 1
    @KGCybeX Usually this code is used in `android{}` section on the same level as `defaultConfig{}`. Although, you can use it outside of `android{}` using `android.applicationVariants.all { }` syntax – Johnny Doe Jan 18 '18 at 11:11
  • @JohnnyDoe Thanks for the help, I have just done as you suggested, no luck. I added to the end of the `android{}` block, still gives error mentioned above -> Gradle with error at bottom https://pastebin.com/Kk2JwPGA – CybeX Jan 18 '18 at 22:54
  • 1
    Work in Gradle 5.1.1 – Williaan Lopes Jul 27 '19 at 03:28
66

Here is a much shorter way:

defaultConfig {
    ...
    applicationId "com.blahblah.example"
    versionCode 1
    versionName "1.0"
    setProperty("archivesBaseName", applicationId + "-v" + versionCode + "(" + versionName + ")")
    //or so
    archivesBaseName = "$applicationId-v$versionCode($versionName)"
}

It gives you name com.blahblah.example-v1(1.0)-debug.apk (in debug mode)

Android Studio add versionNameSuffix by build type name by default, if you want override this, do next:

buildTypes {
    debug {
        ...
        versionNameSuffix "-MyNiceDebugModeName"
    }
    release {
        ...
    }
}

Output in debug mode: com.blahblah.example-v1(1.0)-MyNiceDebugModeName.apk

Anrimian
  • 4,257
  • 4
  • 22
  • 30
55

(EDITED to work with Android Studio 3.0 and Gradle 4)

I was looking for a more complex apk filename renaming option and I wrote this solution that renames the apk with the following data:

  • flavor
  • build type
  • version
  • date

You would get an apk like this: myProject_dev_debug_1.3.6_131016_1047.apk.

You can find the whole answer here. Hope it helps!

In the build.gradle:

android {

    ...

    buildTypes {
        release {
            minifyEnabled true
            ...
        }
        debug {
            minifyEnabled false
        }
    }

    productFlavors {
        prod {
            applicationId "com.feraguiba.myproject"
            versionCode 3
            versionName "1.2.0"
        }
        dev {
            applicationId "com.feraguiba.myproject.dev"
            versionCode 15
            versionName "1.3.6"
        }
    }

    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def project = "myProject"
            def SEP = "_"
            def flavor = variant.productFlavors[0].name
            def buildType = variant.variantData.variantConfiguration.buildType.name
            def version = variant.versionName
            def date = new Date();
            def formattedDate = date.format('ddMMyy_HHmm')

            def newApkName = project + SEP + flavor + SEP + buildType + SEP + version + SEP + formattedDate + ".apk"

            outputFileName = new File(newApkName)
        }
    }
}
Fer
  • 1,956
  • 2
  • 28
  • 35
  • 2
    great. Only improvement to be made is a constant filename (without version or date) for some flavors or buildType (flavor=="dev" || buildType="debug") – Tony BenBrahim Dec 10 '16 at 00:30
  • the "all" instead of "each" seems important here. – Xan-Kun Clark-Davis Jan 26 '20 at 15:32
  • Gives error `> groovy.lang.MissingPropertyException: No such property: variantConfiguration for class: com.android.build.gradle.internal.variant.ApplicationVariantData`. Why not simply change to `buildType = variant.buildType.name`? – soshial Jun 18 '20 at 09:35
  • it says `"file.apk" is not writeable` – Hosein Haqiqian Jul 01 '20 at 07:38
  • You do realize what this line does right "variant.productFlavors[0]"? You will never get actual built product flavor, instead the first flavor that appears in your gradle file. – Farid Jan 16 '21 at 11:59
  • For Android Studio 4 Instead of def buildType = variant.variantData.variantConfiguration.buildType.name Should be def buildType = variant.buildType.name – Volodymyr Jun 11 '21 at 12:26
53

I modified @Abhishek Chaubey answer to change the whole file name:

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                project.ext { appName = 'MyAppName' }
                def formattedDate = new Date().format('yyyyMMddHHmmss')
                def newName = output.outputFile.name
                newName = newName.replace("app-", "$project.ext.appName-") //"MyAppName" -> I set my app variables in the root project
                newName = newName.replace("-release", "-release" + formattedDate)
                //noinspection GroovyAssignabilityCheck
                output.outputFile = new File(output.outputFile.parent, newName)
            }
        }
    }
    debug {
    }
}

This produces a file name like: MyAppName-release20150519121617.apk

Junior Mayhé
  • 16,144
  • 26
  • 115
  • 161
ranma2913
  • 1,058
  • 10
  • 8
  • 3
    How do you add a variable in Gradle – Mehdiway May 21 '15 at 23:39
  • @Mehdiway consider gradle another language, you can see date declared in the code like `def formattedDate`. – Adil Soomro Sep 02 '15 at 05:59
  • 1
    In order to add a custom 'appName' property, add code like this to your root project: `project.ext { appName = 'MyApplicatioName' } ` – miha Jan 24 '16 at 15:09
  • 2
    @ranma2913 I'm not able to run the code through Android Studio anymore after changing the apk name, any idea? please help...it shows The APK file /Users/.../outputs/apk/NewName-debug-20161004172815.apk does not exist on disk. – Beeing Jk Oct 04 '16 at 09:33
  • 2
    Instead of setting manually MyAppName, `rootProject.name` will give you project name like in eclipse. – Hiren Dabhi Oct 14 '16 at 10:55
  • 1
    I prefer doing it in a `build-extras.gradle` file instead to avoid messing up the default one. Also I'm using this for the name of the file to have the package name instead: `"${variant.applicationId}-${variant.name}-${formattedDate}.apk"`, this gives something like `com.mycompany.myapp-release-20161004172815.apk` – Guillaume Mar 09 '17 at 07:09
  • 3
    As of Android Studio 3.0 `output.outputFile` is read only. @johnny-doe's [answer](https://stackoverflow.com/questions/28249036/app-release-apk-how-to-change-this-default-generated-apk-name#46028128) is the new solution. – krishh Oct 07 '17 at 08:37
8

I wrote more universal solution based on @Fer answer.

It also should work with flavor and build type based configuration of applicationId, versionName, versionCode.

In the build.gradle:

android {
    ...
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def appId = variant.applicationId
            def versionName = variant.versionName
            def versionCode = variant.versionCode
            def flavorName = variant.flavorName // e. g. free
            def buildType = variant.buildType // e. g. debug
            def variantName = variant.name // e. g. freeDebug

            def apkName = appId + '_' + variantName + '_' + versionName + '_' + versionCode + '.apk';
            output.outputFile = new File(output.outputFile.parentFile, apkName)
        }
    }
}

Example apk name: com.example.app_freeDebug_1.0_1.apk

For more information about variant variable see ApkVariant and BaseVariant interfaces definition.

KursoR
  • 1,595
  • 13
  • 17
5

add android.applicationVariants.all block like below in you app level gradle

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            lintOptions {
                disable 'MissingTranslation'
            }
            signingConfig signingConfigs.release
            android.applicationVariants.all { variant ->
                variant.outputs.all {
                    outputFileName = "${applicationId}_${versionCode}_${variant.flavorName}_${variant.buildType.name}.apk"
                }
            }
        }
        debug {
            applicationIdSuffix '.debug'
            versionNameSuffix '_debug'
        }
    }

available at 2019/03/25

Loyea
  • 3,359
  • 1
  • 18
  • 19
4

For newer android studio Gradle

AppName is your app name you want so replace it
variantName will be default Selected variant or flavor
Date will Today's date, So need to do any changes just paste it

applicationVariants.all { variant ->
    variant.outputs.all {
        def variantName = variant.name
        def versionName = variant.versionName
        def formattedDate = new Date().format('dd-MM-YYYY')
        outputFileName = "AppName_${variantName}_D_${formattedDate}_V_${versionName}.apk"
    }
}

Output:

AppName_release_D_26-04-2021_V_1.2.apk
Tejas Soni
  • 404
  • 3
  • 4
4

With the flavors and split APK this is how it works for APK files, not the Bundle / AAB files

android {
    ....

    productFlavors {
        aFlavor {
            applicationId "com.a"
        
            versionCode 5
            versionName "1.0.5"

            signingConfig signingConfigs.signingA
        }
        bFlavor {
            applicationId "com.b"

            versionCode 5
            versionName "1.0.5"

            signingConfig signingConfigs.signingB
        }
        cFlavor {
            applicationId "com.c"

            versionCode 3
            versionName "1.0.3"

            signingConfig signingConfigs.signingC
        }
    }

    splits {
        abi {
            enable true
            reset()
            include 'arm64-v8a', 'x86', 'x86_64'
            universalApk false
        }
    }

    android.applicationVariants.all { variant ->
        variant.outputs.all { output ->
            // New one or Updated one
            output.outputFileName = "${variant.getFlavorName()}-${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}-${output.getFilter(com.android.build.OutputFile.ABI)}.apk"
            // Old one
            // output.outputFileName = "${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}.apk"
        }
    }
}

Result

For aFlvour

  • Release

    aFlavor-release-v5_1.0.5-16Jan2020_21-26-arm64-v8a.apk

    aFlavor-release-v5_1.0.5-16Jan2020_21-26-x86_64.apk

    aFlavor-release-v5_1.0.5-16Jan2020_21-26-x86.apk

  • Debug

    aFlavor-debug-v5_1.0.5-16Jan2020_21-26-arm64-v8a.apk

    aFlavor-debug-v5_1.0.5-16Jan2020_21-26-x86_64.apk

    aFlavor-debug-v5_1.0.5-16Jan2020_21-26-x86.apk

For bFlavor

Similar name as above just change the prefix aFlavor with bFlavor like

  • bFlavor-release-v5_1.0.5-16Jan2020_21-26-arm64-v8a.apk

For cFlavor

Similar name as above just change the prefix aFlavor with cFlavor and, versionCode and versionName as respected

  • cFlavor-release-v3_1.0.3-16Jan2020_21-26-arm64-v8a.apk

For more detail review this Que-Ans thread

Mihir Trivedi
  • 1,458
  • 18
  • 39
3

Not renaming it, but perhaps generating the name correctly in the first place would help? Change apk name with Gradle

Community
  • 1
  • 1
bryan
  • 798
  • 7
  • 18
3

I've realised that a lot of the answers didn't cater for different buildTypes, here is how I handle it.

applicationVariants.all { variant ->
   variant.outputs.all {                                       
      def appVersionName = "${applicationId}v${versionCode}#${versionName}"
      
      switch (buildType.name) {
          case "debug": {  
              outputFileName = "${appVersionName}-staging.apk"                                            
              break
          }
         case "release": {
              outputFileName = "${appVersionName}.apk"
              break
          }
      }
   }
}

Attributes like applicationId, versionCode and versionName are already defined in your defaultConfig. You can just easily format into something that gives it a more meaningful and context naming whenever you generate an APK.

This is how it'll churn out.

com.delacrixmorgan-v1.0.0#1.apk
com.delacrixmorgan-v1.0.0#1-staging.apk

Besides that, if you guys want to learn more about Gradle. I've went into length in this Medium article. Supercharging your Android Gradle

Morgan Koh
  • 2,297
  • 24
  • 24
  • Unrotunately `case` doesn't work for me, so I made it easier: `def name = "${applicationId}-${versionName}-${versionCode}"; def suffix = buildType.name == 'debug' ? '-debug' : ''; outputFileName = "${name}${suffix}.apk";` – ezze Feb 08 '22 at 10:59
2

First rename your module from app to i.e. SurveyApp

Second add this to your project top-level (root project) gradle. It's working with Gradle 3.0

//rename apk for all sub projects
subprojects {
    afterEvaluate { project ->
        if (project.hasProperty("android")) {
            android.applicationVariants.all { variant ->
                variant.outputs.all {
                    outputFileName = "${project.name}-${variant.name}-${variant.versionName}.apk"
                }
            }
        }
    }
}
Qamar
  • 4,959
  • 1
  • 30
  • 49
2

Add the following code in build.gradle(Module:app)

android {
    ......
    ......
    ......
    buildTypes {
        release {
            ......
            ......
            ......
            /*The is the code fot the template of release name*/
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def formattedDate = new Date().format('yyyy-MM-dd HH-mm')
                    def newName = "Your App Name " + formattedDate
                    output.outputFile = new File(output.outputFile.parent, newName)
                }
            }
        }
    }
}

And the release build name will be Your App Name 2018-03-31 12-34

Vinil Chandran
  • 1,563
  • 1
  • 19
  • 33
1

My solution may also be of help to someone.

Tested and Works on IntelliJ 2017.3.2 with Gradle 4.4

Scenario:

I have 2 flavours in my application, and so I wanted each release to be named appropriately according to each flavor.

The code below will be placed into your module gradle build file found in:

{app-root}/app/build.gradle

Gradle code to be added to android{ } block:

android {
    // ...

    defaultConfig {
        versionCode 10
        versionName "1.2.3_build5"
    }

    buildTypes {
        // ...

        release {
            // ...

            applicationVariants.all { 
                variant.outputs.each { output ->
                    output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(output.outputFile.name, variant.flavorName + "-" + defaultConfig.versionName + "_v" + defaultConfig.versionCode + ".apk"))
                }
            }

        }
    }

    productFlavors {
        myspicyflavor {
            applicationIdSuffix ".MySpicyFlavor"
            signingConfig signingConfigs.debug
        }

        mystandardflavor {
            applicationIdSuffix ".MyStandardFlavor"
            signingConfig signingConfigs.config
        }
    }
}

The above provides the following APKs found in {app-root}/app/:

myspicyflavor-release-1.2.3_build5_v10.apk
mystandardflavor-release-1.2.3_build5_v10.apk

Hope it can be of use to someone.

For more info, see other answers mentioned in the question

CybeX
  • 2,060
  • 3
  • 48
  • 115
1

android studio 4.1.1

applicationVariants.all { variant ->
  variant.outputs.all { output ->
    def reversion = "118"
    def date = new java.text.SimpleDateFormat("yyyyMMdd").format(new Date())
    def versionName = defaultConfig.versionName
    outputFileName = "MyApp_${versionName}_${date}_${reversion}.apk"
  }
}
Hun
  • 3,652
  • 35
  • 72
1

Here i made my apk name

branchName_versionName_versionCode.apk

example

development_1.5.3_10.apk

get branch name from here

def getBranchName = { ->
    try {
        def stdout = new ByteArrayOutputStream()
        exec {
            commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD'
            standardOutput = stdout
        }
        println "Git Current Branch = " + stdout.toString()
        return stdout.toString().trim()
    }
    catch (Exception e) {
        println "Exception = " + e.getMessage()
        return null;
    }
}

then get your variants from here and set file name

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def appId = variant.applicationId
        def versionName = variant.versionName
        def versionCode = variant.versionCode
        def flavorName = variant.flavorName // e. g. free
        def buildType = variant.buildType // e. g. debug
        def variantName = variant.name // e. g. freeDebug

        def apkName = getBranchName() + '_' + versionName + '_' + versionCode + '.apk';
        output.outputFileName = apkName
    }
}

Put this script in android tag in app/build.gradle file

android {
def getBranchName ................
..................
..................
applicationVariants.all ..........
..................
..................
}
Muhamed El-Banna
  • 593
  • 7
  • 21
0

I think this will be helpful.

buildTypes {
    release {
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                project.ext { appName = 'MyAppName' }
                def formattedDate = new Date().format('yyyyMMddHHmmss')
                def newName = output.outputFile.name
                newName = newName.replace("app-", "$project.ext.appName-")
                newName = newName.replace("-release", "-release" + formattedDate)
                output.outputFile = new File(output.outputFile.parent, newName)
            }
        }
    }
}
productFlavors {
    flavor1 {
    }
    flavor2 {
        proguardFile 'flavor2-rules.pro'
    }
}
Black_Dreams
  • 572
  • 1
  • 5
  • 11
0

put this code in build.gradle(app)

 android {

      .......
     applicationVariants.all { variant ->
            variant.outputs.all {
                outputFileName = "Name_of_App.apk"
            }}
         }
Mark Nashat
  • 668
  • 8
  • 9
0

Simplest way - in build.gradle(app):

android {
    compileSdk 31
    project.archivesBaseName = "Scanner"

    defaultConfig {

And - you will receive : Scanner-release.apk

0

Hope this will work.

Kotlin : 1.8.20 Android Studio : Android Studio Giraffe | 2022.3.1 Gradle : gradle-7.5.1-bin.zip

android {    
  ..............

applicationVariants.all { variant ->
        def formattedDate = new Date().format('yyyyMMdd')
        def flavorName = "${variant.flavorName}"
        def buildName = variant.buildType.name
        def versionName = variant.versionName
        def versionCode = variant.versionCode
        def fileName = "${formattedDate}_HELLO_Android_${flavorName}_${buildName}_v${versionName}(${versionCode}).apk"
        variant.outputs.all {
            outputFileName = fileName
        }
    }

}

Preview :

20230822_HELLO_Android_appStoreLive_debug_v4.2.4(196).apk

Yogendra
  • 4,817
  • 1
  • 28
  • 21