我正在使用带有 Gradle 构建的 Android Studio。在我的build.gradle中,我希望变量的值对于不同的构建类型是不同的:
ext {
//By default, the value of myVar is 'debug'
myVar = 'debug'
}
android {
buildTypes {
release {
//update value of myVar to 'release'
project.ext.set("myVar","release")
}
debug {
//update value of myVar to 'debug'
project.ext.set("myVar","debug")
}
}
}
//I defined a task to check the value of myVar
task checkVar () {
println "My var is $myVar"
}
check.dependsOn(checkVar)
当我运行命令gradle clean assembleRelease
时,我希望看到一个打印出来的文本My var is release
。但是,我明白了My var is debug
。为什么 的值myVar
没有更改为release
?
我想要实现的是在执行期间获取当前的构建类型。有没有更好的方法来实现这一目标?