diff --git a/MPChartExample/build.gradle b/MPChartExample/build.gradle index 422a0a7755..32d07c30a7 100644 --- a/MPChartExample/build.gradle +++ b/MPChartExample/build.gradle @@ -9,8 +9,8 @@ android { applicationId "com.xxmassdeveloper.mpchartexample" minSdkVersion 19 targetSdkVersion 33 - versionCode 57 - versionName '3.1.0' + versionCode getGitCommitCount() + versionName getTag() testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunnerArguments useTestStorageService: 'true' } diff --git a/MPChartLib/build.gradle b/MPChartLib/build.gradle index 7bd72f9c7f..31c826dc6d 100644 --- a/MPChartLib/build.gradle +++ b/MPChartLib/build.gradle @@ -9,6 +9,10 @@ android { minSdkVersion 19 targetSdkVersion 33 + // VERSION_NAME no longer available as of 4.1 + // https://issuetracker.google.com/issues/158695880 + buildConfigField 'String', 'VERSION_NAME', "\"${getTag()}\"" + consumerProguardFiles 'proguard-project.txt' } buildTypes { diff --git a/build.gradle b/build.gradle index c458934f88..9fc6aee8ac 100644 --- a/build.gradle +++ b/build.gradle @@ -18,3 +18,15 @@ allprojects { mavenCentral() } } + +@SuppressWarnings('unused') +static def getTag() { + def process = "git describe --tags --abbrev=0".execute() + return process.text.toString().trim() +} + +@SuppressWarnings('unused') +static def getGitCommitCount() { + def process = "git rev-list HEAD --count".execute() + return process.text.toInteger() +}