Autoincrement VersionCode with gradle extra properties

前端 未结 16 2253
逝去的感伤
逝去的感伤 2020-11-27 08:47

I\'m building an Android app with gradle. Until now I used the Manifest file to increase the versionCode, but I would like to read the versionCode from an external file and

16条回答
  •  青春惊慌失措
    2020-11-27 09:28

    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 {
        ...
    }
    

提交回复
热议问题