在要更新您的build.gradle,我已經改變了一個腳本編輯當前的版本。 gradle並遞增versionCode和versionName。如果你想運行./gradlew bintrayUpload
何時更新版本
task incrementVersionCode << {
println("Incrementing Version Code...")
def manifestFile = file("build.gradle")
def patternVersionCode = Pattern.compile("versionCode (\\d+)")
def manifestText = manifestFile.getText()
def matcherVersionCode = patternVersionCode.matcher(manifestText)
matcherVersionCode.find()
def mVersionCode = Integer.parseInt(matcherVersionCode.group(1))
def mNextVersionCode = mVersionCode + 1
def manifestContent = matcherVersionCode.replaceAll("versionCode " + mNextVersionCode)
println("> Set versionCode(" + mVersionCode + ") to " + mNextVersionCode);
manifestFile.write(manifestContent)
}
task incrementVersionName << {
println("Incrementing Version Name...")
def manifestFile = file("build.gradle")
def patternVersionNumber = Pattern.compile("versionName \"(\\d+)\\.(\\d+)\\.(\\d+)\"")
def manifestText = manifestFile.getText()
def matcherVersionNumber = patternVersionNumber.matcher(manifestText)
matcherVersionNumber.find()
def majorVersion = Integer.parseInt(matcherVersionNumber.group(1))
def minorVersion = Integer.parseInt(matcherVersionNumber.group(2))
def pointVersion = Integer.parseInt(matcherVersionNumber.group(3))
def mVersionName = majorVersion + "." + minorVersion + "." + pointVersion
def mNextVersionName = majorVersion + "." + minorVersion + "." + (pointVersion + 1)
def manifestContent = matcherVersionNumber.replaceAll("versionName \"" + mNextVersionName + "\"")
println("> Set versionName(" + mVersionName + ") to " + mNextVersionName);
manifestFile.write(manifestContent)
}
使用
(用於例如,物也可以是你想要的任務)補充一點:
這個任務添加到您的gradle產出:
bintrayUpload.dependsOn incrementVersionCode
bintrayUpload.dependsOn incrementVersionName
可能的重複[如何在Android Gradle中自動增加versionCode](http://stackoverflow.com/questions/17448565/how-to-autoincre – 2015-04-02 12:24:25
@EdGeorge它不同於如何在Android Gradle中自動增量versionCode,因爲versionCode和versioName存儲在build.gradle中,而不是在清單中 – 2015-04-02 12:35:40
上面的帖子顯示了兩種技術,不同於任何這些解決方案,並完成相同的任務,它應作爲回答發佈在該問題上,而不是作爲其自己的問題 – 2015-04-02 12:39:10