如何阅读在build.gradle local.properties定义的属性 [英] How do i read properties defined in local.properties in build.gradle
本文介绍了如何阅读在build.gradle local.properties定义的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经设置sdk.dir和ndk.dir在local.properties。
I have set sdk.dir and ndk.dir in local.properties.
我要如何阅读sdk.dir和ndk.dir在build.gradle文件中定义的值?
How do i read the values defined in sdk.dir and ndk.dir in the build.gradle file?
推荐答案
您可以做,在这种方式:
You can do that in this way:
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def sdkDir = properties.getProperty('sdk.dir')
def ndkDir = properties.getProperty('ndk.dir')
使用 project.rootProject
如果你正在阅读的一个子项目 build.gradle
属性文件:
Use project.rootProject
if you are reading the properties file in a sub-project build.gradle
:
.
├── app
│ ├── build.gradle <-- You are reading the local.properties in this gradle build file
│ └── src
├── build.gradle
├── gradle
├── gradlew
├── gradlew.bat
├── settings.gradle
└── local.properties
在情况下,属性文件是在同一个子项目目录,你可以只使用项目
。
In case the properties file is in the same sub-project directory you can use just project
.
这篇关于如何阅读在build.gradle local.properties定义的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文