mm
(make) command to build this application Because I have to change and build this app again and again, so I want to add a build time stamp in the Contacts.apk
to check the build time when we runn it in the handset.
As we know, when we run mm
command, the Android.mk
(makefile) in Contacts package will be called.
And now, we can get the build time using date
-macro.
But how we can write this build time stamp into a file that our application can read at runtime?
Any suggestions?
Creating a Signed APK File To generate a signed APK file, open the Build menu from the toolbar and select Generate Signed Bundle/APK. This opens up a screen where you have to select between creating an Android App Bundle and creating an APK file.
Method which checks date of last modification of classes.dex, this means last time when your app's code was built:
try{ ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), 0); ZipFile zf = new ZipFile(ai.sourceDir); ZipEntry ze = zf.getEntry("classes.dex"); long time = ze.getTime(); String s = SimpleDateFormat.getInstance().format(new java.util.Date(time)); zf.close(); }catch(Exception e){ }
Tested, and works fine, even if app is installed on SD card.
If you use Gradle, you can add buildConfigField
with timestamp updated at build time.
android { defaultConfig { buildConfigField "long", "TIMESTAMP", System.currentTimeMillis() + "L" } }
Then read it at runtime.
Date buildDate = new Date(BuildConfig.TIMESTAMP);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With