如何自动增量版本code在Android的摇篮增量、摇篮、版本、code

由网友(夕阳坠落旳很沧桑°)分享简介:我有新的Andr​​oid版本系统的基础上尝试摇篮,我在想,什么是autoincrease版本code与它的最好办法。我想两个选项I'm experimenting with new Android build system based on Gradle and I'm thinking, what is the...

我有新的Andr​​oid版本系统的基础上尝试摇篮,我在想,什么是autoincrease版本code与它的最好办法。我想两个选项

I'm experimenting with new Android build system based on Gradle and I'm thinking, what is the best way to autoincrease versionCode with it. I am thinking about two options

创建的版本code文件,从中读取次数,增加它,并把它写回文件 解析AndroidManifest.xml中,读版本code从它,增加它,并把它写回的Andr​​oidManifest.xml

有没有更简单的或适合的解决方案?

Is there any more simple or suitable solution?

有没有人使用mentiod选项之一,可以与我分享呢?

Has anyone used one of mentiod options and could share it with me?

推荐答案

我已经决定了第二个方案 - 解析的Andr​​oidManifest.xml 。这里正在片段。

I have decided for second option - to parse AndroidManifest.xml. Here is working snippet.

task('increaseVersionCode') << {
    def manifestFile = file("AndroidManifest.xml")
    def pattern = Pattern.compile("versionCode="(d+)"")
    def manifestText = manifestFile.getText()
    def matcher = pattern.matcher(manifestText)
    matcher.find()
    def versionCode = Integer.parseInt(matcher.group(1))
    def manifestContent = matcher.replaceAll("versionCode="" + ++versionCode + """)
    manifestFile.write(manifestContent)
}

tasks.whenTaskAdded { task ->
    if (task.name == 'generateReleaseBuildConfig') {
        task.dependsOn 'increaseVersionCode'
    }
}

版本code 发布的发布版本在这种情况下。为了增加它的调试版本更改 task.whenTaskAdded 回调task.name式。

versionCode is released for release builds in this case. To increase it for debug builds change task.name equation in task.whenTaskAdded callback.

阅读全文

相关推荐

最新文章