Skip to content

Commit

Permalink
Set build time in debug version from Gradle instead of classes.dex
Browse files Browse the repository at this point in the history
  • Loading branch information
bparmentier committed May 8, 2017
1 parent 69c2a4a commit 6b755d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ android {
targetSdkVersion 22
versionCode 22
versionName "1.9.2"
buildConfigField "long", "BUILD_TIMESTAMP", System.currentTimeMillis() + "L"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
Expand All @@ -28,13 +27,10 @@
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.text.format.DateFormat;
import android.util.Log;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import be.brunoparmentier.openbikesharing.app.BuildConfig;
import be.brunoparmentier.openbikesharing.app.R;
Expand Down Expand Up @@ -94,18 +90,11 @@ private void setupVersionEntry() {
versionName = getActivity().getPackageManager()
.getPackageInfo(getActivity().getPackageName(), 0).versionName;
if (BuildConfig.DEBUG) {
/* https://stackoverflow.com/a/7608719/3997816 */
ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(getActivity().getPackageName(), 0);
ZipFile zf = new ZipFile(ai.sourceDir);
ZipEntry ze = zf.getEntry("classes.dex");
zf.close();
long time = ze.getTime();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmdd");

versionName += "-debug-" + dateFormat.format(time);
String buildTime = DateFormat.format("yyyyMMddHHmmdd", new java.util.Date(BuildConfig.BUILD_TIMESTAMP)).toString();
versionName += "-debug-" + buildTime;
}
versionPref.setSummary(versionName);
} catch (PackageManager.NameNotFoundException | IOException e) {
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, e.getMessage());
}
}
Expand Down

0 comments on commit 6b755d4

Please sign in to comment.