Created
February 25, 2022 04:41
-
-
Save shailesh17/9bf0d9cbcf659bc2d1bfabd717ca67fc to your computer and use it in GitHub Desktop.
Android versionCode versionName
This file contains 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
//see https://developer.android.com/google/play/publishing/multiple-apks#VersionCodes | |
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