Skip to content

Commit

Permalink
Use git describe --tags --dirty as the versionName (getodk#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 authored and lognaturel committed Jan 6, 2017
1 parent d80e4c7 commit 13f966b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
26 changes: 25 additions & 1 deletion collect_app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ apply plugin: 'checkstyle'

com.android.ddmlib.DdmPreferences.setTimeOut(60000)

ant.condition(property: "os", value: "windows") { os(family: "windows") }
ant.condition(property: "os", value: "unix" ) { os(family: "unix") }

def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
switch(ant.properties.os){
case 'windows':
commandLine 'cmd', '/c', 'git', 'describe', '--tags', '--dirty'
break
case 'unix':
commandLine 'git', 'describe', '--tags', '--dirty'
break
}
standardOutput = stdout
}
return stdout.toString().trim()
}
catch (ignored) {
return null;
}
}

android {
compileSdkVersion(22)
buildToolsVersion("25.0.0")
Expand All @@ -16,7 +40,7 @@ android {
minSdkVersion(9)
targetSdkVersion(9)
versionCode(1063)
versionName("1.4.12")
versionName getVersionName()
testInstrumentationRunner("android.support.test.runner.AndroidJUnitRunner")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import android.app.Application;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -109,18 +108,17 @@ public static int getQuestionFontsize() {
}

public String getVersionedAppName() {
String versionDetail = "";
String versionName = "";
try {
PackageInfo pinfo;
pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
int versionNumber = pinfo.versionCode;
String versionName = pinfo.versionName;
versionDetail = " " + versionName + " (" + versionNumber + ")";
versionName = getPackageManager()
.getPackageInfo(getPackageName(), 0)
.versionName;
versionName = " " + versionName.replaceFirst("-", "\n");
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return getString(R.string.app_name) + versionDetail;
return getString(R.string.app_name) + versionName;
}

/**
Expand Down

0 comments on commit 13f966b

Please sign in to comment.