日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

android build获取ext,android – 如何在Gradle中获取当前构建类型

發布時間:2025/3/20 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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中获取当前构建类型的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。