Android的版本的Gradle如何设置全局变量 [英] Android gradle build: how to set global variables
本文介绍了Android的版本的Gradle如何设置全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何设置,可以从的build.gradle和任务进行访问的全局变量?
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
有关更多信息,请参见:<一href=\"http://www.gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html\">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
修改:
正如评论德米特里·,在新版本中,你可以使用以下简写:
EDIT: As commented by Dmitry, In new versions you can use the following shorthand:
project.ext.variableName = value
这篇关于Android的版本的Gradle如何设置全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文