【问题标题】:Cannot add task ':app:reportSourceSetTransformTest' as a task with that name already exists无法添加任务“:app:reportSourceSetTransformTest”,因为具有该名称的任务已存在
【发布时间】:2018-10-02 19:46:12
【问题描述】:
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'
}

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 谢谢!那也是我的问题。我必须将我的测试风味的名称更改为其他名称(离线),并且还必须将测试文件夹更改为离线,其中我有风味特定的类
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 2019-08-02
    • 2016-07-10
    • 2013-03-21
    相关资源
    最近更新 更多