summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gradle/scripts/git-scm-version.gradle24
-rw-r--r--navit/android/build.gradle5
2 files changed, 27 insertions, 2 deletions
diff --git a/gradle/scripts/git-scm-version.gradle b/gradle/scripts/git-scm-version.gradle
new file mode 100644
index 000000000..a0d518a86
--- /dev/null
+++ b/gradle/scripts/git-scm-version.gradle
@@ -0,0 +1,24 @@
+//THX to https://proandroiddev.com/configuring-android-project-version-name-code-b168952f3323
+
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath 'org.ajoberstar:grgit:2.3.0'
+ }
+}
+
+import org.ajoberstar.grgit.Grgit
+import java.time.format.DateTimeFormatter
+
+ext {
+ git = Grgit.open(currentDir: projectDir)
+ gitVersionName = git.describe(match: ["v[0-9.rc]*"])
+ gitVersionCode = Integer.parseInt(DateTimeFormatter.ofPattern("yyMMddhhmm").format(git.head().dateTime))
+}
+
+task printVersion() {
+ println("Version Name: $gitVersionName")
+ println("Version Code: $gitVersionCode")
+}
diff --git a/navit/android/build.gradle b/navit/android/build.gradle
index ca9dab255..e2e42bc80 100644
--- a/navit/android/build.gradle
+++ b/navit/android/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
+apply from: "$project.rootDir/gradle/scripts/git-scm-version.gradle"
apply plugin: 'checkstyle'
android {
@@ -8,8 +9,8 @@ android {
applicationId "org.navitproject.navit"
minSdkVersion 9
targetSdkVersion 27
- versionCode 1
- versionName "1.0"
+ versionCode gitVersionCode
+ versionName gitVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk { // need for now for 'x86_64' and , 'armeabi' and , 'arm64-v8a'
abiFilters 'x86', 'armeabi-v7a'