无法添加任务':app:reportSourceSetTransformTest',因为该名称的任务已经存在

时间:2018-09-10 12:24:05

标签: android gradle android-gradle build.gradle

Minimum supported gradle version 4.6 Current version is 4.4.

将gradle版本更新为4.6后,出现此错误

Cannot add task ':app:reportSourceSetTransformTest' as a task with that name already exists.

如何避免此错误。似乎两个不同的文件具有相同的任务。但是我没有在应用程序级别的build.gradle文件中找到任何任务或未明确定义任何任务。

我的项目级别build.gradle文件是这样的:

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
        maven { url 'https://maven.google.com' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
        maven { url 'https://maven.google.com' }
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

和应用级build.gradle文件是这样的:

apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.1'
    flavorDimensions "default"
    defaultConfig {
        applicationId "com.applicationId"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 3
        versionName "1.0.2"
        vectorDrawables.useSupportLibrary = true
    }
    aaptOptions {
        cruncherEnabled = false
    }
    lintOptions {
        abortOnError false
        checkReleaseBuilds false
    }
  }

dependencies {
    implementation project(':demo')
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    androidTestImplementation('junit:junit:4.12')
    implementation 'com.github.ViksaaSkool:AwesomeSplash:v1.0.0'
}

1 个答案:

答案 0 :(得分:3)

就我而言,我的口味名称和新的gradle插件发生冲突。 当我更改口味的名称(生产,测试)->(生产,开发)时,该问题已解决