安卓/ Gradle : conditionally apply plugin based on build type

标签 android gradle android-gradle-plugin build.gradle gradle-plugin

我想做一些类似的东西(伪代码):

if (BuildType == "release"){
    apply plugin: 'testfairy'
} else if (BuildType == "debug"){
    apply plugin: 'io.fabric'
}

这个想法是基于构建类型,应用(或不应用)一个插件。怎么做?

最佳答案

对于 Gradle 4.6,以下工作:

if (getGradle().getStartParameter().getTaskRequests().toString().contains("Release")) {
    apply plugin: 'testfairy'
} else if (getGradle().getStartParameter().getTaskRequests().toString().contains("Debug")) {
    apply plugin: 'io.fabric'
}

关于安卓/ Gradle : conditionally apply plugin based on build type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36039793/

相关文章:

java - 回收站 View : Inner classes cannot have static declaration

android - 为什么显示 InputType 密码?

android - 使用 Android 模拟器连接到 IIS Express

java - 使用 Java 9 JDK 定位 Java 6 会发出警告

gradle - 如何在目标文件夹的 gradle 复制任务中使用参数?

android - 如何在不同的Android Studio模块中使用同一个gradle依赖的不同版本?

android - 我怎样才能看到缩小代码的效果

Android SQLite 3,JOINS 还是多个查询?

gradle - 获取 gradle 以忽略 jar 名称中的版本号

android - 使用Android Studio时如何获取Android库的源代码?