0

Im using this code to show App compilation date:

ApplicationInfo ai = a.getPackageManager().getApplicationInfo(a.getPackageName(), 0);
        ZipFile zf = new ZipFile(ai.sourceDir);
        ZipEntry ze = zf.getEntry("META-INF/MANIFEST.MF");
        long time = ze.getTime() + (3600000 * 2);
        Log.i("date", new SimpleDateFormat("HH:mm:ss dd.MM.yyyy").format(new Date(time)));
        zf.close();

Yesterday everything was fine but today (after Android Studio upgrade ???) everytime It shows

02:00:00 30.11.1979

??? I have already Cleaned and Rebuilt project. What is wrong here?

MattiahIT
  • 87
  • 9

2 Answers2

1

Ok I have an answer from: How to write build time stamp into apk

Best option is using Timestamp in Gradle

android {
defaultConfig {
    buildConfigField "long", "TIMESTAMP", System.currentTimeMillis() + "L"
}

}

Date buildDate = new Date(BuildConfig.TIMESTAMP);

Thanks :)

Community
  • 1
  • 1
MattiahIT
  • 87
  • 9
1

According to response #3 on this Google Issue, the ZipFile method of obtaining the build date can still be used as long as "android.keepTimestampsInApk = true" is set in Gradle properties.

Gradle intentionally zeroes out the build timestamps unless that property is set.

Egg
  • 1,986
  • 16
  • 20