Skip to content

Instantly share code, notes, and snippets.

@maxirosson
Last active December 28, 2022 12:02
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save maxirosson/48c0d8160c758a9145e6 to your computer and use it in GitHub Desktop.
Save maxirosson/48c0d8160c758a9145e6 to your computer and use it in GitHub Desktop.
Versioning Android apps
apply plugin: 'com.android.application'
ext.versionMajor = 1
ext.versionMinor = 2
ext.versionPatch = 3
ext.versionClassifier = null
ext.isSnapshot = true
ext.minimumSdkVersion = 19
android {
compileSdkVersion 27
buildToolsVersion "27.0.0"
defaultConfig {
applicationId "com.sample"
targetSdkVersion 27
minSdkVersion project.ext.minimumSdkVersion
versionCode generateVersionCode() // 190010203
versionName generateVersionName() // 1.2.3-SNAPSHOT
}
}
private Integer generateVersionCode() {
return ext.minimumSdkVersion * 10000000 + ext.versionMajor * 10000 + ext.versionMinor * 100 + ext.versionPatch
}
private String generateVersionName() {
String versionName = "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}"
if (ext.versionClassifier == null && ext.isSnapshot) {
ext.versionClassifier = "SNAPSHOT"
}
if (ext.versionClassifier != null) {
versionName += "-" + ext.versionClassifier
}
return versionName;
}
@bsodmike
Copy link

bsodmike commented Sep 9, 2016

Hi Maxi

For example, when the application version name is 3.1.0, the version code for a minimum API level 4 APK would be something like 040030100. The first two digits are reserved for the minimum API Level (4 in this case), the third digit is for either screen sizes or GL texture formats (not used in this example, so a 0 is assigned), and the last six digits are for the application’s version name (3.1.0).

I've got my minimum screensize set to 600dp for tablets, how can I setup the third digit — and my actual question is how are you 'changing' this number so I can plan accordingly.

Thanks!!

@dineshmm23
Copy link

dineshmm23 commented May 30, 2018

Hi what does ext means here? How does it helps?

ext.versionMajor = 1
ext.versionMinor = 2
ext.versionPatch = 3
ext.versionClassifier = null
ext.isSnapshot = true
ext.minimumSdkVersion = 15

@pvdrdeena
Copy link

can you help me on how to integrate this gradle file in CI/CD to pass incremental values automatically to these variables for every build
ext.versionMajor = 1
ext.versionMinor = 2
ext.versionPatch = 3

@HaneetGH
Copy link

Hi

what will be the max limit for
private Integer generateVersionCode() {
return ext.minimumSdkVersion * 10000000 + ext.versionMajor * 10000 + ext.versionMinor * 100 + ext.versionPatch
}

this
when app version is 9999.9999.9999 is present

will this work?

@maxirosson
Copy link
Author

Hi. This is explained here: https://medium.com/dipien/versioning-android-apps-d6ec171cfd82
The maximum supported version will be 99.99.99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment