@@ -2,15 +2,19 @@ apply plugin: 'com.android.application'
22apply plugin : ' kotlin-android'
33apply plugin : ' kotlin-android-extensions'
44
5+ int vCode = 20000 + getVersionCode() // The last code is 20001, make sure the result is greater than it.
6+ String vName = getVersionName()
7+ logger. lifecycle(" App Version: $vName ($vCode )" )
8+
59android {
610 compileSdkVersion 29
711 buildToolsVersion ' 29.0.3'
812 defaultConfig {
913 applicationId " cc.chenhe.qqnotifyevo"
1014 minSdkVersion 26
1115 targetSdkVersion 29
12- versionCode 20001
13- versionName " 2.0.1 "
16+ versionCode vCode
17+ versionName vName
1418 }
1519 buildTypes {
1620 release {
@@ -50,7 +54,7 @@ dependencies {
5054 exclude group : ' com.android.support' , module : ' support-annotations'
5155 })
5256 implementation " androidx.preference:preference-ktx:1.1.1"
53- implementation " androidx.core:core-ktx:1.3.0 "
57+ implementation " androidx.core:core-ktx:1.3.1 "
5458 implementation " org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version "
5559 implementation ' com.oasisfeng.nevo:sdk:2.0.0-rc01'
5660 implementation " com.jakewharton.timber:timber:4.7.1"
@@ -62,3 +66,21 @@ dependencies {
6266repositories {
6367 mavenCentral()
6468}
69+
70+
71+ private static int getVersionCode () {
72+ def cmd = ' git rev-list HEAD --first-parent --count'
73+ cmd. execute(). text. trim(). toInteger()
74+ }
75+
76+ private static String getVersionName () {
77+ def cmd = ' git describe --tags --long --first-parent --abbrev=7 --dirty="-dev"'
78+ def v = cmd. execute(). text. trim()
79+ def matcher = v =~ / ^v([\d |.]+)-\d +-g[A-Za-z0-9]{7}(-dev)?$/
80+
81+ if (! matcher) {
82+ throw new RuntimeException (" Cannot match git tag name. raw=$v " )
83+ }
84+ def suffix = matcher[0 ][2 ] ? matcher[0 ][2 ] : ' '
85+ " ${ matcher[0][1]} $suffix "
86+ }
0 commit comments