Android gradle build:如何设置全局变量 [英] Android gradle build: how to set global variables

查看:28
本文介绍了Android gradle build:如何设置全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置可以从 build.gradle 和 tasks 访问的全局变量?

How can I set a global variable that can be accessed from build.gradle and tasks?

推荐答案

设置全局变量

project.ext.set("variableName", value)

从项目中的任何地方访问它:

To access it from anywhere in the project:

project.variableName

例如:

project.ext.set("newVersionName", versionString)

然后……

println project.newVersionName

有关详细信息,请参阅:http://www.gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html

For more information see: http://www.gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html

编辑:正如 Dmitry 所说,在新版本中,您可以使用以下简写:

EDIT: As commented by Dmitry, In new versions you can use the following shorthand:

project.ext.variableName = value

这篇关于Android gradle build:如何设置全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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