Skip to content

Instantly share code, notes, and snippets.

@amannepid
Created August 8, 2016 04:15
Show Gist options
  • Save amannepid/cfda044aae7f4821cf27e6fb20d30013 to your computer and use it in GitHub Desktop.
Save amannepid/cfda044aae7f4821cf27e6fb20d30013 to your computer and use it in GitHub Desktop.
Generate APK with version names and date
// This gist is tested with gradle version 2.1.2
// Create a method outside android { .... }
// Built apk file naming: AppName-VersionName-Date-BuildType.apk
def getBuildFileName(versionName) {
def date = new Date().format('yyyy-MMM-dd')
def appName
if(project.hasProperty("applicationName")){
appName = applicationName
}else {
appName = parent.name
}
return "${appName}-${versionName}-${date}"
}
android {
....
....
defaultConfig {
applicationId "<app_id>"
minSdkVersion <min_sdk>
targetSdkVersion <target_sdk>
versionCode 71000
// Major -> Millions, Minor -> Thousands, Bug fix -> Hundreds. E.g 1.3.72 == 1,003,072
versionName "0.71.0"
setProperty("archivesBaseName",getBuildFileName(versionName))
}
...
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment