- Making some changes in Android Contacts package
- Using
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?
Method which checks date of last modification of classes.dex, this means last time when your app's code was built:
Tested, and works fine, even if app is installed on SD card.
Both are differnet time. You can check with the code below.
So Android Developer - Android Studio User Guide - Gradle Tips and Recipes - Simplify App Development actually documents what to add in order to have a release timestamp available to your app:
I'm including this here since all of the other solutions appear to be from before the official example.
If you use Gradle, you can add
buildConfigField
with timestamp updated at build time.Then read it at runtime.
I know this is really old, but here's how I did it using ant within eclipse:
build.xml in project root
Then add an application_build_date string to your strings.xml
Ensure the ant script is executed as a pre-build activity and you will always have a valid build date available to you within R.string.application_build_date.
Since API version 9 there's:
PackageInfo.lastUpdateTime
The time at which the app was last updated.
On lower API versions you must make build time yourself. For example putting a file into assets folder containing the date. Or using __ DATE__ macro in native code. Or checking date when your classes.dex was built (date of file in your APK).