从bash中的build.gradle读取versionName [英] Read versionName from build.gradle in bash

查看:424
本文介绍了从bash中的build.gradle读取versionName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从Android项目的build.gradle文件中读取值versionName并在bash中使用它?

Is there a way to read the value versionName from the build.gradle file of an Android project to use it in bash?

更准确地说:如何从文件中读取此值并将其在Travis-CI脚本中使用?我会像这样使用它

More precisely: How can I read this value from the file and use it in a Travis-CI script? I'll use it like

# ANDROID_VERSION=???
export GIT_TAG=build-$ANDROID_VERSION

我按照本文 https://stackoverflow.com/a/28230711/1700776我的build.gradle: http://pastebin.com/uiJ0LCSk

My build.gradle: http://pastebin.com/uiJ0LCSk

推荐答案

扩展Khozzy的答案,以从build.gradle检索Android包的versionName,添加以下自定义任务:

Expanding on Khozzy's answer, to retrieve versionName of your Android package from the build.gradle, add this custom task:

task printVersionName {
    doLast {
        println android.defaultConfig.versionName
    }
}

并调用它:

gradle -q printVersionName

这篇关于从bash中的build.gradle读取versionName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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