如何在使用gradle构建时将git提交和分支信息插入到apk中? [英] How to insert the commit and branch info from git to the apk when building with gradle?

查看:88
本文介绍了如何在使用gradle构建时将git提交和分支信息插入到apk中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有很多开发人员和很多设备以及大量新鲜和旧版的apk。有时会发生不良行为。我需要检测设备上安装的apk版本(哪些分支,最后一次提交,上次提交时哪些文件被更改,当apk压缩时)。

我们使用Gradle从项目中创建apk。

是否有任何方法(指令或插件或脚本)将版本信息放置在apk中的某个位置?例如,作为java类中的常量或资源中的文本文件。

 任务gitInfo<< {
ext.revision = getGitRevParseInfo(--short)
ext.branch = getGitRevParseInfo(--abbrev-ref)

println ext.revision
println ext.branch

$ b $ def getGitRevParseInfo(什么){
def cmd =git rev-parse+ what +HEAD
def proc = cmd.execute()
proc.text.trim()
}

因此,您可以使用 ext 来为android应用程序构建 versionName


We have lots of developers and lots of devices and lots of fresh and old versions of apk. Sometimes bad behaviour is occurred. I need to detect what version of the apk is installed on the device (what branch, what last commit, what files was changed from last commit, when apk criated).

We use Gradle to make apk from projects.

Is there any method (directive or plugin or script) to place the version information somewhere in the apk? For example, as constant in java class or as text file in resources.

解决方案

You could use next snippet:

task gitInfo << {
   ext.revision = getGitRevParseInfo ( "--short" )
   ext.branch = getGitRevParseInfo ( "--abbrev-ref" )

   println ext.revision
   println ext.branch
}

def getGitRevParseInfo (what) {
   def cmd = "git rev-parse " + what + " HEAD"
   def proc = cmd.execute ()
   proc.text.trim ()
}

So you can use ext for constructing versionName for android app

这篇关于如何在使用gradle构建时将git提交和分支信息插入到apk中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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