使用git describe和Gradle进行Android构建的自动版本控制 [英] Automatic versioning of Android build using git describe with Gradle

查看:82
本文介绍了使用git describe和Gradle进行Android构建的自动版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了广泛的搜索,但是可能是由于Android Studio和Gradle的新颖性.我尚未找到有关如何执行此操作的任何说明.我基本上想做的完全是

I have searched extensively, but likely due to the newness of Android Studio and Gradle. I haven't found any description of how to do this. I want to do basically exactly what is described in this post, but with Android Studio, Gradle and Windows rather than Eclipse and Linux.

推荐答案

获得最近成功的结果的一种更正确,更精益的方法是使用 Groovy JGit绑定实现git集成.由于它使用JGit,因此甚至不需要安装git就可以正常工作.

A more proper and lean way to achieve the result which gained traction lately would be to use gradle git integration via Groovy JGit bindings. As it uses JGit it doesn't even require git to be installed to work.

这是一个基本示例,显示了类似的解决方案(但在gitVersionName字符串中包含一些其他信息):

Here's a basic example showing a similar (but with some additional information in gitVersionName string) solution:

buildscript {
  dependencies {
    classpath 'org.ajoberstar:grgit:1.4.+'
  }
}
ext {
  git = org.ajoberstar.grgit.Grgit.open()
  gitVersionCode = git.tag.list().size()
  gitVersionName = "${git.describe()}"
}
android {
  defaultConfig {
    versionCode gitVersionCode
    versionName gitVersionName
  }
}
[...]

您可以在 Grgit API文档中看到

As you can see in Grgit API documentation the describe operation provides additional information other than most recent tag reachable in history:

查找可从HEAD访问的最新标签.如果标签指向提交,则仅显示标签.否则,它会在标记名称后加上标记对象后附加的提交次数以及最近提交的缩写对象名称.

Find the most recent tag that is reachable from HEAD. If the tag points to the commit, then only the tag is shown. Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit.

无论如何,它不会告诉您状态是否肮脏.可以通过查看回购协议的清除状态轻松添加此信息,然后如果不干净,则附加一个字符串.

Anyhow, it won't tell if the state is dirty or not. This information can be easily added by looking at the clean status of the repo, and appending a string if it's not clean.

这篇关于使用git describe和Gradle进行Android构建的自动版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆