From 0eee6f58e808be4f61b70c0f1a02fe71c98c5709 Mon Sep 17 00:00:00 2001 From: Vahagn Khachatryan Date: Sat, 9 Oct 2021 23:25:06 +0100 Subject: [PATCH] Generating git version string through resValue. --- app/build.gradle | 63 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 71eee4c..b2964a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,38 +4,6 @@ plugins { apply plugin: "androidx.navigation.safeargs" -// -// Creates version.xml -// -task createVersionXML { - doLast { - def versionP = 'git describe --tags --long --dirty=-x --always --abbrev=8' - .execute() - versionP.waitFor() - def version = versionP.text.trim() - if ( versionP.exitValue() ) - throw new GradleException("Couldn't extract version. Git exited unexpectedly.") - - def githashP = 'git rev-parse HEAD'.execute() - githashP.waitFor() - def githash = githashP.text.trim() - if ( githashP.exitValue() ) - throw new GradleException("Couldn't extract git_hash. Git exited unexpectedly.") - - def builddate = new Date() - def versionFile = new FileWriter("app/src/main/res/values/version.xml") - versionFile.println( '' ) - versionFile.println( '' ) - versionFile.println( '' << version << '' ) - versionFile.println( '' << githash << '' ) - versionFile.println( '' << builddate << '' ) - versionFile.println( '0x00020001' ) - versionFile.println( '' ) - versionFile.close() - } -} -preBuild.dependsOn createVersionXML - // // Convert SVG images from art directory into PNG files. // @@ -51,7 +19,34 @@ preBuild.dependsOn createVersionXML //} //preBuild.dependsOn generateDrawablesFromArt +String gitVersion() { + def versionP = 'git describe --tags --long --dirty=-x --always --abbrev=8' + .execute() + versionP.waitFor() + if (versionP.exitValue()) + throw new GradleException("Couldn't extract version. Git exited unexpectedly.") + return versionP.text.trim() +} + +String gitHash() { + def githashP = 'git rev-parse HEAD'.execute() + githashP.waitFor() + if (githashP.exitValue()) + throw new GradleException("Couldn't extract git_hash. Git exited unexpectedly.") + return githashP.text.trim() +} + +String buildDate() { + def builddate = new Date() + return builddate.toString() +} + android { + signingConfigs { + release { + storeFile file('/Users/vahagnk/devel/banvor/keys/signing_key') + } + } compileSdk 31 defaultConfig { @@ -63,6 +58,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" resValue "bool", "debug_visible", "false" + resValue "string", "git_version", gitVersion() + resValue "string", "git_hash", gitHash() + resValue "string", "build_date", buildDate() + // resValue "string", "version_code", "0x00020001" } buildTypes { release {