自动版本Android项目从混帐与Android工作室/摇篮描述 [英] Automatically versioning Android project from git describe with Android Studio/Gradle

查看:325
本文介绍了自动版本Android项目从混帐与Android工作室/摇篮描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我寻觅广泛,但可能是由于Android的Studio和摇篮的新奇,我还没有找到如何做到这一点任何说明。我想基本上做究竟是什么在<一个描述href="http://stackoverflow.com/questions/14895123/auto-version-numbering-your-android-app-using-git-and-eclipse-on-linux">this帖子,但与Android工作室,摇篮和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.

推荐答案

一个更恰当的和精益的方式来实现其获得牵引力最近是使用的摇篮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:

buildscript {
  dependencies {
    classpath 'org.ajoberstar:grgit:1.4.+'
  }
}
ext {
  git = org.ajoberstar.grgit.Grgit.open(file('.'))
  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:

查找最新的标记,它是从头部到达。如果该标记指向的提交,则仅标记示出。否则,它后缀标​​签名称与附加提交对加标签的物体的顶部和最新的缩写对象名称数提交

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.

但无论如何,它不会告诉我们,如果状态是脏与否。这些信息可以通过查看href="https://github.com/ajoberstar/gradle-git/issues/63" rel="nofollow">回购的清洁状态的

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.

这篇关于自动版本Android项目从混帐与Android工作室/摇篮描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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