日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2025/3/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android build获取ext,android – 如何在Gradle中获取当前构建类型 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我的問題非常直接且易于理解.

在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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。