【发布时间】:2018-05-04 16:11:31
【问题描述】:
我的问题很直接,很容易理解。
问题
在 Gradle 中,有什么方法可以在运行时获取当前的构建类型。例如,在运行 assembleDebug 任务时,build.gradle 文件中的任务是否可以根据该任务与调试构建变体相关的事实做出决策?
示例代码
apply plugin: 'com.android.library'
ext.buildInProgress = ""
buildscript {
repositories {
maven {
url = url_here
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
configurations {
//get current build in progress here e.g buildInProgress = this.getBuildType()
}
android {
//Android build settings here
}
buildTypes {
release {
//release type details here
}
debug {
//debug type details here
}
anotherBuildType{
//another build type details here
}
}
}
dependencies {
//dependency list here
}
repositories{
maven(url=url2_here)
}
task myTask{
if(buildInProgress=='release'){
//do something this way
}
else if(buildInProgress=='debug'){
//do something this way
}
else if(buildInProgress=='anotherBuildType'){
//do it another way
}
}
总结
有没有办法让我在 myTask{} 中准确获取正在进行的构建类型?
【问题讨论】:
-
您找到解决方案了吗?我正在尝试解决下一个任务stackoverflow.com/questions/52677223/…
标签: android android-studio gradle android-gradle-plugin build.gradle