其他分享
首页 > 其他分享> > 使用带有Gradle的git describe自动版本化Android构建

使用带有Gradle的git describe自动版本化Android构建

作者:互联网

我进行了广泛的搜索,但可能是由于Android Studio和Gradle的新功能.我还没有找到如何做到这一点的任何描述.我想基本上完成this post中描述的内容,但使用Android Studio,Gradle和Windows而不是Eclipse和Linux.

解决方法:

实现最近获得牵引力的结果的更合适和精益的方式是使用gradle git integration通过Groovy JGit bindings.因为它使用JGit它甚至不需要安装git来工作.

这是一个显示类似(但在gitVersionName字符串中有一些附加信息)解决方案的基本示例:

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 documentation中所见,describe operation提供了除历史记录中可访问的最新标记之外的其他信息:

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.

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

标签:android,git,gradle,android-build,auto-versioning
来源: https://codeday.me/bug/20190919/1812828.html