android build获取ext,android – 如何在Gradle中获取当前构建类型
我的問題非常直接且易于理解.
題
在Gradle中,有什么辦法可以在運行時獲取當(dāng)前的構(gòu)建類型.例如,在運行assembleDebug任務(wù)時,build.gradle文件中的任務(wù)是否可以根據(jù)此任務(wù)與調(diào)試構(gòu)建變量相關(guān)的事實做出決策?
示例代碼
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 {}中獲得正在進(jìn)行的構(gòu)建類型?
解決方法:
您可以通過解析applicationVariants來獲取確切的構(gòu)建類型:
applicationVariants.all { variant ->
buildType = variant.buildType.name // sets the current build type
}
實現(xiàn)可能如下所示:
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問題幫助提問者解決問題.
標(biāo)簽:android,android-gradle,android-studio,build-gradle,gradle
來源: https://codeday.me/bug/20190823/1697494.html
總結(jié)
以上是生活随笔為你收集整理的android build获取ext,android – 如何在Gradle中获取当前构建类型的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 精通android布局,Android精
- 下一篇: android listview ite