-
-
Save virendersran01/b73d97b77b01d03ae4c3d1ee74424ae9 to your computer and use it in GitHub Desktop.
Versioning Android apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment