Naz*_*Jnr 11 android gradle android-studio build.gradle android-gradle-plugin
我的问题很直接,很容易理解。
题
在Gradle中,有什么方法可以在运行时获取当前的构建类型。例如,在运行汇编Debug任务时,build.gradle文件中的任务是否可以基于该任务与debug build变体相关的事实来做出决策?
样例代码
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
}
}
Run Code Online (Sandbox Code Playgroud)
综上所述
有没有办法让我的myTask {}中的构建类型准确进行?
Unl*_*uto 10
您可以通过解析以下内容来获取确切的构建类型applicationVariants
:
applicationVariants.all { variant ->
buildType = variant.buildType.name // sets the current build type
}
Run Code Online (Sandbox Code Playgroud)
一个实现可能如下所示:
def buildType // Your variable
android {
applicationVariants.all { variant ->
buildType = variant.buildType.name // Sets the current build type
}
}
task myTask{
// Compare buildType here
}
Run Code Online (Sandbox Code Playgroud)
更新资料
归档时间: |
|
查看次数: |
6187 次 |
最近记录: |