Add Application Name and Version Name in Generated APK

Hi Everyone, Have a great day. Happy Feb.

How to add app name, version name in the generated apk? 

- It's very interesting question asked by my junior developer.


In app.gradle

Under the android

just add following line:

project.archivesBaseName = "IndAppz";


more?

add the version information:

Put the following code under the buildTypes.


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

even more?

add the app with date information:

define the date:
def getDate() {
    new Date().format('ddMMMyyyy')
}

And then add the date info into the file name.

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


Comments

Popular posts from this blog

Flutter Bloc - Clean Architecture

What's new in android 14?

Dependencies vs Dev Dependencies in Flutter