From c779ef333e85d13c34e8686beccf8893e1c20880 Mon Sep 17 00:00:00 2001 From: David Allison <62114487+david-allison@users.noreply.github.com> Date: Sun, 27 Aug 2023 17:04:11 +0800 Subject: [PATCH] dev: add git commit hash to debug info Output: AnkiDroid Version = 2.16.3-debug (edf739d95bad7b370a6ed4398d46723f8219b3cd) While I have a development build on my Android emulator, sometimes I encounter a bug, this makes the build much more visible to help with diagnostics --- AnkiDroid/build.gradle | 9 +++++++++ .../java/com/ichi2/anki/servicelayer/DebugInfoService.kt | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/AnkiDroid/build.gradle b/AnkiDroid/build.gradle index 49fb2c18430f..ea1e4d402cd6 100644 --- a/AnkiDroid/build.gradle +++ b/AnkiDroid/build.gradle @@ -25,6 +25,14 @@ idea { } def homePath = System.properties['user.home'] +/** + * @return the current git hash + * @example edf739d95bad7b370a6ed4398d46723f8219b3cd + */ +static def gitCommitHash() { + "git rev-parse HEAD".execute().text.trim() +} + android { namespace "com.ichi2.anki" @@ -43,6 +51,7 @@ android { buildConfigField "String", "BACKEND_VERSION", "\"$ankidroid_backend_version\"" buildConfigField "Boolean", "ENABLE_LEAK_CANARY", "false" buildConfigField "Boolean", "ALLOW_UNSAFE_MIGRATION", "false" + buildConfigField "String", "GIT_COMMIT_HASH", "\"${gitCommitHash()}\"" resValue "string", "app_name", "AnkiDroid" // The version number is of the form: diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/DebugInfoService.kt b/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/DebugInfoService.kt index 2c0b4a944046..f862c40225c1 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/DebugInfoService.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/DebugInfoService.kt @@ -42,7 +42,7 @@ object DebugInfoService { val webviewUserAgent = getWebviewUserAgent(info) val newSchema = !BackendFactory.defaultLegacySchema return """ - AnkiDroid Version = $pkgVersionName + AnkiDroid Version = $pkgVersionName (${BuildConfig.GIT_COMMIT_HASH}) Android Version = ${Build.VERSION.RELEASE}