Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

" app-release.apk" how to change this default generated apk name

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

like image 643
Prabs Avatar asked Oct 09 '22 11:10

Prabs


People also ask

How do I change the name of an APK file?

Navigate to the folder in which your apk is present. In that folder select your APK file. Right-click on it and click on rename option to rename your APK file.

Can I rename app debug APK?

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.

How do I format an APK file?

Create a Signed APK FileCreate the project in Android Studio. Select Build > Signed Bundle/APK from the toolbar menu. Configure the settings for your APK file and possibly create a new key store and key.

What is APK stand for?

An APK (Android Package Kit) is the file format for applications used on the Android operating system. APK files are compiled with Android Studio, which is the official integrated development environment (IDE) for building Android software. An APK file includes all of the software program's code and assets.


3 Answers

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. :)

like image 73
Abhishek Chaubey Avatar answered Oct 23 '22 09:10

Abhishek Chaubey


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.
like image 28
Johnny Doe Avatar answered Oct 23 '22 11:10

Johnny Doe


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

like image 63
Anrimian Avatar answered Oct 23 '22 09:10

Anrimian