我有这个:
def loadProperties(String sourceFileName) {
def config = new Properties()
def propFile = new File(sourceFileName)
if (propFile.canRead()) {
config.load(new FileInputStream(propFile))
for (Map.Entry property in config) {
ext[property.key] = property.value;
}
}
}
loadProperties 'gradle.properties'
如何在build.gradle中引用属性(ndk.dir)?
def ndkBuild = new File("$ndk.dir", 'ndk-build')
有没有更好的方法从gradle.properties文件中读取ndk.dir?如何在使用中使用它?
def ndkBuild = new File("$ndk.dir", 'ndk-build')
完整代码:
task buildNative(type: Exec) {
loadProperties 'gradle.properties'
if (System.getenv('NDK_HOME') != null || "$ndk.dir" != null) {
if ("$ndk.dir" != null) {
def ndkBuild = new File("$ndk.dir", 'ndk-build')
} else {
def ndkBuild = new File(System.getenv('NDK_HOME'), 'ndk-build')
}
workingDir "jni"
executable ndkBuild
} else {
throw new GradleException('Reason: NDK_HOME not set or ndk.dir is missing in gradle.properties...')
}
}
def loadProperties(String sourceFileName) {
def config = new Properties()
def propFile = new File(sourceFileName)
if (propFile.canRead()) {
config.load(new FileInputStream(propFile))
for (Map.Entry property in config) {
ext[property.key] = property.value;
}
}
}