How to write build time stamp into apk

后端 未结 10 644
别跟我提以往
别跟我提以往 2020-12-02 07:57
  1. Making some changes in Android Contacts package
  2. Using mm (make) command to build this application

Because I have to change and

10条回答
  •  没有蜡笔的小新
    2020-12-02 08:03

    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:

    android {
      ...
      buildTypes {
        release {
          // These values are defined only for the release build, which
          // is typically used for full builds and continuous builds.
          buildConfigField("String", "BUILD_TIME", "\"${minutesSinceEpoch}\"")
          resValue("string", "build_time", "${minutesSinceEpoch}")
          ...
        }
        debug {
          // Use static values for incremental builds to ensure that
          // resource files and BuildConfig aren't rebuilt with each run.
          // If they were dynamic, they would prevent certain benefits of
          // Instant Run as well as Gradle UP-TO-DATE checks.
          buildConfigField("String", "BUILD_TIME", "\"0\"")
          resValue("string", "build_time", "0")
        }
      }
    }
    ...
    

    In your app code, you can access the properties as follows:

    ...
    Log.i(TAG, BuildConfig.BUILD_TIME);
    Log.i(TAG, getString(R.string.build_time));
    

    I'm including this here since all of the other solutions appear to be from before the official example.

提交回复
热议问题