29

Every time I run a project with Android Studio (1.02) it's generate an unsigned apk which located in ..\build\outputs\apk folder and get by default the name "app-debug.apk"

I want to change that default name to something else.

Is it possible? How?

Elnatan Derech
  • 987
  • 2
  • 12
  • 18

8 Answers8

33

In build.gradle (Module: app):

android {
    ...
    defaultConfig {
        ...
        setProperty("archivesBaseName", "MyNewAppNameGoesHere")
    }
}

This works by modifying the archivesBaseName-property and works for Gradle Version >= 2.0, last tested with 2.1.0.

Murmel
  • 5,402
  • 47
  • 53
27

You can use applicationVariants and change the output file in the build.gradle. You can also modify the name regarding to your needs.

buildTypes{

    applicationVariants.all { variant ->                              
        variant.outputs.each { output ->                              
            output.outputFile = file("$project.buildDir/apk/test.apk")
        }                                                             
    }

}
Orhan Obut
  • 8,756
  • 5
  • 32
  • 42
  • I am getting below error while changing it. Maybe doing something wron. Please let me know. A problem occurred configuring project ':app'. > groovy.lang.GroovyRuntimeException: Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{variantOutput=VariantOutputImpl(versionCode=property(java.lang.Integer, provider(class java.lang.Integer)),.... – sameer pradhan Mar 04 '21 at 09:20
13

Solution for gradle3:

android.applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = applicationId;
        outputFileName += "-v" + android.defaultConfig.versionName;
        if (variant.buildType.name == "release") {
            outputFileName += ".apk";
        } else {
            outputFileName += "-SNAPSHOT.apk";
        }
    }
}
elcuco
  • 8,948
  • 9
  • 47
  • 69
4
defaultConfig {  

    applicationId "com.dcarl661.awesomelayout"

    minSdkVersion 14

    targetSdkVersion 25

    versionCode 1

    versionName "1.0"

    //here put it in the section where you have the version stuff
    setProperty("archivesBaseName", "AwesomeLayout")

}
t.m.adam
  • 15,106
  • 3
  • 32
  • 52
4
defaultConfig {
    applicationId "com.example"


    def date = new Date();
    def formattedDate = date.format('yyyy-MM-dd-HHmmss')
    setProperty("archivesBaseName", "Quest_" + versionName + "_"+formattedDate)
}

i did like this. More detailed

Arjun
  • 358
  • 2
  • 13
3

If anyone is looking to change apk name outside the Android studio(just to send this file to someone else, as in my case), just right click the app name and change it to whatever you want.

shaby
  • 1,301
  • 1
  • 15
  • 17
2

The 'app' part of the name uses the folder name of your application's module (default is 'app'). See the link below on how to change that.
Why is my APK name generic?

The '-debug' prefix is something you can change in the Module settings at Build Types

Community
  • 1
  • 1
pklinken
  • 179
  • 1
  • 4
0

Maybe this question (and its accepted answer) are interesting for you: How to set versionName in APK filename using gradle? It describes how to put your versionName into the APK name.

You have to use the 'Update' part of the accepted answer. Also you need the versionName (in this example) declared in your defaultConfig in the build.gradle file. It does also work if you define versionCode in the build.gradle (as described here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Manifest-entries ).

Community
  • 1
  • 1
Valentin Kuhn
  • 753
  • 9
  • 25