Auto increment version code in Android app

后端 未结 15 1000
忘掉有多难
忘掉有多难 2020-12-07 08:22

is there a way to auto-increment the version code each time you build an Android application in Eclipse?

According to http://developer.android.com/guide/publishing/v

15条回答
  •  一整个雨季
    2020-12-07 08:29

    Receipe:

    To automatically have the android:versionCode attribute of manifest element in AndroidManifest.xml set to the current time (from epoch in seconds, obtained from unix shell) everytime you run a build, add this to your -pre-build target in custom_rules.xml Android file.

    
      
        
      
      
    
    

    Confirmation Test:

    Obtain the versionCode attribute of the generated apk file, using the following shell command from your Android project directory :

    $ANDROID_SDK/build-tools/20.0.0/aapt dump badging bin/.apk | grep versionCode
    

    and compare it to the current date returned from the shell command: date +%s The difference should equal the period of time in seconds between the two confirmation steps above.

    Advantages of this approach:

    1. Regardless of whether the build is started from command line or Eclipse, it will update the versionCode.
    2. The versionCode is guaranteed to be unique and increasing for each build
    3. The versionCode can be reverse-engineered into an approximate build time if you need it
    4. The above script replaces any present value of versionCode, even 0 and doesn't require a macro place holder (such as -build_id-).
    5. Because the value is updated in the AndroidManifest.xml file, you can check it in to version control and it will retain the actual value, not some macro (such as -build_id-).

提交回复
热议问题