Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@bsodmike 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

This comment has been minimized.

Copy link

@dineshmm23 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

This comment has been minimized.

Copy link

@pvdrdeena pvdrdeena commented May 15, 2019

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

This comment has been minimized.

Copy link

@HaneetGH HaneetGH commented Dec 21, 2020

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

This comment has been minimized.

Copy link
Owner Author

@maxirosson maxirosson commented Dec 24, 2020

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