本文介紹了如何讀取 build.gradle 中 local.properties 中定義的屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我在local.properties
中設置了sdk.dir
和ndk.dir
.
如何讀取build.gradle
文件中sdk.dir
和ndk.dir
中定義的值?
How do I read the values defined in sdk.dir
and ndk.dir
in the build.gradle
file?
推薦答案
你可以這樣做:
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def sdkDir = properties.getProperty('sdk.dir')
def ndkDir = properties.getProperty('ndk.dir')
如果您正在讀取子項目 build.gradle
中的屬性文件,請使用 project.rootProject
:
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
如果屬性文件在同一個子項目目錄中,您可以只使用 project
.
In case the properties file is in the same sub-project directory you can use just project
.
這篇關于如何讀取 build.gradle 中 local.properties 中定義的屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!