Auto increment version code in Android app

后端 未结 15 999
忘掉有多难
忘掉有多难 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:43

    There are two solutions I really like. The first depends on the Play Store and the other depends on Git.

    Using the Play Store, you can increment the version code by looking at the highest available uploaded version code. The benefit of this solution is that an APK upload will never fail since your version code is always one higher than whatever is on the Play Store. The downside is that distributing your APK outside of the Play Store becomes more difficult. You can set this up using Gradle Play Publisher by following the quickstart guide and telling the plugin to resolve version codes automatically:

    plugins {
        id 'com.android.application'
        id 'com.github.triplet.play' version 'x.x.x'
    }
    
    android {
        ...
    }
    
    play {
        serviceAccountCredentials = file("your-credentials.json")
        resolutionStrategy = "auto"
    }
    

    Using Git, you can increment the version code based on how many commits and tags your repository has. The benefit here is that your output is reproducible and doesn't depend on anything outside your repo. The downside is that you have to make a new commit or tag to bump your version code. You can set this up by adding the Version Master Gradle plugin:

    plugins {
        id 'com.android.application'
        id 'com.supercilex.gradle.versions' version 'x.x.x'
    }
    
    android {
        ...
    }
    

提交回复
热议问题