Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

android - How to write build time stamp into apk

  1. Making some changes in Android Contacts package
  2. 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...