Generate signed APK file with Specific name Android Studio

In Android Studio, when clicked menu Build-> Generate Signed APK file, the dialogs displayed for generating APK file, doesn’t allow you to edit the APK file name. It just applies default app name to build file, unlike ADT Eclipse.


We have to write Groovy code in Gradle build file to, Generate singed APK file with Specific name.

Here i’m just giving an example how we can write it.
For eg: If your app name is helloWorld, If you generate APK build file, it will creates helloWorld-release.apk file. But if you want to generate Apk file with appending version name, and change filename like “HelloWorld-1.0v.apk”.

In project open build.gradle file, you should have defaultConfig as below

defaultConfig {
    applicationId "com.sample.helloworld"
    minSdkVersion 14
    targetSdkVersion 14
    versionCode 1
    versionName '1.0'

in this build.gradle file, define a method just above the dependencies, as below

def appendVersionName(variant, defaultConfig) {
    variant.outputs.each { output ->
        if (output.zipAlign) {
            def file = output.outputFile
            def fileName ="helloWorld-release.apk", "HelloWorld-" + defaultConfig.versionName  + "v.apk")
            output.outputFile = new File(file.parent, fileName)

        def file = output.packageApplication.outputFile
        def fileName ="helloWorld-release.apk", "HelloWorld-" + defaultConfig.versionName + "v.apk")
        output.packageApplication.outputFile = new File(file.parent, fileName)

dependencies {
    compile files('libs/android-support-v13.jar')
    compile ''

then search for buildTypes, and call the appendVersionName method as shown below,

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

            applicationVariants.all { variant ->
                appendVersionName(variant, defaultConfig)


That’s it. Now Goto Build-> Generate a Signed APK… just follow the dialog, click Finish, and you will see APK file created with your specified name.

Hope it helps somebody…

Cheers.. 🙂

ref link & credits:

You may also interested in


  1. Ray | | Reply

    Does not work at all. 🙁 I hate Google with their stupid idiotic Android Studio!

    • Praveen | | Reply

      @Ray, Yes I agree. I wish i could help on this. I’ll try to create a sample app and attach to this post soon, may be this weekend. Thanks

  2. emre | | Reply

    hello there. i did the same but my file name neither versionName nor verisonCode become “null”
    like 20151029_hello_null.apk . why it become null ? what should i do ? Can you help? thank you

Leave a Reply

Your email address will not be published. Required fields are marked *