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

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

问题描述

我进行了广泛的搜索,但可能是由于 Android Studio 和 Gradle 的新特性.我还没有找到任何关于如何做到这一点的描述.我想基本上完全按照 这篇文章,但使用的是 Android Studio、Gradle 和 Windows,而不是 Eclipse 和 Linux.

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.

推荐答案

实现最近获得关注的结果的一种更恰当和精益的方法是使用 gradle git 集成 通过 Groovy JGit 绑定.由于它使用 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:

plugins {
  id 'org.ajoberstar.grgit' version '4.1.0'
}
ext {
  gitVersionCode = grgit.tag.list().size()
  gitVersionName = grgit.describe(tags: true, always: true)
}
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.

无论如何,它不会告诉状态是否脏.通过查看 repo 的 clean status,可以轻松添加此信息,如果不干净,则附加一个字符串.

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天全站免登陆