android build获取ext,android – 如何在Gradle中获取当前构建类型
我的问题非常直接且易于理解.
题
在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 {}中获得正在进行的构建类型?
解决方法:
您可以通过解析applicationVariants来获取确切的构建类型:
applicationVariants.all { variant ->
buildType = variant.buildType.name // sets the current build type
}
实现可能如下所示:
def buildType // Your variable
android {
applicationVariants.all { variant ->
buildType = variant.buildType.name // Sets the current build type
}
}
task myTask{
// Compare buildType here
}
您也可以查看this和this类似的答案.
更新
This回答this问题帮助提问者解决问题.
标签:android,android-gradle,android-studio,build-gradle,gradle
来源: https://codeday.me/bug/20190823/1697494.html
总结
以上是生活随笔为你收集整理的android build获取ext,android – 如何在Gradle中获取当前构建类型的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 精通android布局,Android精
- 下一篇: android listview ite