Add git commit hash and branch information to AboutActivity for debug builds

This will help us differentiate between custom/debug builds and release builds
of Aegis.
This commit is contained in:
Alexander Bakker 2019-09-07 21:17:32 +02:00
parent 1d513441c6
commit cbe3697d68
2 changed files with 22 additions and 13 deletions

View file

@ -1,5 +1,17 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
def getCmdOutput = { cmd ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine cmd
standardOutput = stdout
}
return stdout.toString().trim()
}
def getGitHash = { -> return getCmdOutput(["git", "rev-parse", "--short", "HEAD"]) }
def getGitBranch = { -> return getCmdOutput(["git", "rev-parse", "--abbrev-ref", "HEAD"]) }
android { android {
compileSdkVersion 28 compileSdkVersion 28
@ -9,6 +21,8 @@ android {
targetSdkVersion 28 targetSdkVersion 28
versionCode 21 versionCode 21
versionName "1.0.2" versionName "1.0.2"
buildConfigField "String", "GIT_HASH", "\"${getGitHash()}\""
buildConfigField "String", "GIT_BRANCH", "\"${getGitBranch()}\""
} }
lintOptions { lintOptions {
@ -80,5 +94,4 @@ dependencies {
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
} }

View file

@ -1,15 +1,13 @@
package com.beemdevelopment.aegis.ui; package com.beemdevelopment.aegis.ui;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import com.beemdevelopment.aegis.Preferences; import com.beemdevelopment.aegis.BuildConfig;
import com.beemdevelopment.aegis.R; import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.Theme; import com.beemdevelopment.aegis.Theme;
import com.beemdevelopment.aegis.helpers.ThemeHelper; import com.beemdevelopment.aegis.helpers.ThemeHelper;
@ -22,7 +20,6 @@ import androidx.core.view.LayoutInflaterCompat;
import de.psdev.licensesdialog.LicenseResolver; import de.psdev.licensesdialog.LicenseResolver;
import de.psdev.licensesdialog.LicensesDialog; import de.psdev.licensesdialog.LicensesDialog;
import de.psdev.licensesdialog.licenses.License;
public class AboutActivity extends AegisActivity { public class AboutActivity extends AegisActivity {
@ -48,7 +45,7 @@ public class AboutActivity extends AegisActivity {
btnLicenses.setOnClickListener(v -> showLicenseDialog()); btnLicenses.setOnClickListener(v -> showLicenseDialog());
TextView appVersion = findViewById(R.id.app_version); TextView appVersion = findViewById(R.id.app_version);
appVersion.setText(getCurrentVersion()); appVersion.setText(getCurrentAppVersion());
View btnGithub = findViewById(R.id.btn_github); View btnGithub = findViewById(R.id.btn_github);
btnGithub.setOnClickListener(v -> openUrl(GITHUB)); btnGithub.setOnClickListener(v -> openUrl(GITHUB));
@ -74,13 +71,12 @@ public class AboutActivity extends AegisActivity {
}); });
} }
private String getCurrentVersion() { private static String getCurrentAppVersion() {
try { if (BuildConfig.DEBUG) {
return getPackageManager().getPackageInfo(getPackageName(), 0).versionName; return String.format("%s-%s (%s)", BuildConfig.VERSION_NAME, BuildConfig.GIT_HASH, BuildConfig.GIT_BRANCH);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} }
return "Unknown version";
return BuildConfig.VERSION_NAME;
} }
private void openUrl(String url) { private void openUrl(String url) {