java - 错误 : Cannot add task 'clean' as a task with that name already exists

标签 java android android-gradle-plugin retrofit

我在使用 Gradle 构建时遇到问题。这是我面临的错误:

ERROR: Cannot add task 'clean' as a task with that name already exists.

这是我的 Gradle

apply plugin: 'com.android.application'android {
compileSdkVersion 28
buildToolsVersion "25.0.1"
defaultConfig {
    applicationId "net.accedegh.retrofitlibrary"
    minSdkVersion 17
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "com.android.support:recyclerview-v7:28.0.0"
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.picasso:picasso:2.4.0'
implementation 'com.github.jd-alexander:LikeButton:0.2.0'
implementation'com.github.bumptech.glide:glide:3.7.0'compile 'com.github.varunest:sparkbutton:1.0.3'
implementation 'com.android.support:design:28.0.0'
androidTestCompile 'junit:junit:4.12'}

顶级build.gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules. 
buildscript { 
    repositories { 
        jcenter() 
        google() 
    } 

   dependencies { 
        classpath 'com.android.tools.build:gradle:3.3.2' 
       // NOTE: Do not place your application dependencies here; they belong 
       // in the individual module build.gradle files 
   } 
} 

allprojects { 
    repositories { 
        maven { 
            url 'maven.google.com' 
            name 'Google' 
        } 
    } 

    task clean(type: Delete) { 
        delete rootProject.buildDir 
    } 
}

有知道的请给我解答

最佳答案

您在项目级 build.gradle 中定义了此任务(如您的评论中所述):

task clean(type: Delete) { 
    delete rootProject.buildDir 
}

Android Studio 的 Gradle 包装器已经定义了一个 clean 任务,所以不需要重新定义它。只需从您的项目级 build.gradle 文件中删除该任务即可。

关于java - 错误 : Cannot add task 'clean' as a task with that name already exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55118903/

相关文章:

java - Android:显示进度条对话框时出现问题?

java - 如何在java web项目运行时在webroot中创建文件?

Android Studio 重命名模块

java - 通过 JDBC 将 CSV 内容加载到 mysql 数据库中?

java - EXP4J 的可变参数?如何?

java - 如何在 MavenCentral 中发布不同于 "release"的构建变体

android - 将时间戳系统属性从Gradle传递到Android(Java)应用程序

具有唯一应用程序 ID 的 Android 产品风格

java - 在 main 中调用一个类

java - 文档监听器有时会触发,但其他时候则不会