Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build release apk with customize name format in Android Studio

I want the .apk to be built with the following name format (with timestamp).

How can I set it?

format : {app_name}{yyyymmddhis}.apk

Now, it is fixed with the name {app_name}-{release}.apk

like image 370
LoGary Avatar asked Jul 09 '14 08:07

LoGary


People also ask

How can I change APK name in Android Studio?

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 change APK name?

If you want to change the apk file name, you should change your project name. To do this, you just right click on your project in Navigator windows, choose Refactor>Rename and type a new name for it.

What is the difference between debug APK and release APK?

Major differences are the debug apk and the release apk: For debug builds the apk will be signed with the default debug signing keys with debug flag enabled. For release apk you will have to explicitly specify the apk to sign with and the debug flag will be turned off so that it cannot be debugged.


1 Answers

in the build.gradle file, you should change/add buildTypes like this:

buildTypes {
      release {
        signingConfig signingConfigs.release
        applicationVariants.all { variant ->
            def file = variant.outputFile
            def date = new Date();
            def formattedDate = date.format('yyyyMMddHHmmss')
            variant.outputFile = new File(
                                    file.parent, 
                                    file.name.replace("-release", "-" + formattedDate)
                                    )
        }
    }       
}


====== EDIT with Android Studio 1.0 ======

If you are using Android Studio 1.0, you will get an error like this:

Error:(78, 0) Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@67e7625f.

You should change the build.Types part to this:

buildTypes {
        release {
            signingConfig signingConfigs.releaseConfig
            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)
                                            )
                }
            }
        }
    }
like image 80
Wesley Avatar answered Oct 26 '22 03:10

Wesley