首页 > 解决方案 > 无法应用插件 [class 'org.gradle.language.base.plugins.LifecycleBasePlugin']

问题描述

我只是在 android studio 上打开一个旧项目,当我尝试在模拟器上运行应用程序时,我看到了这个错误

Build file 'D:\Courses\Java\Android Projects\CustomListViewExample\app\build.gradle' line: 1

A problem occurred evaluating project ':app'.
> Failed to apply plugin [class 'org.gradle.language.base.plugins.LifecycleBasePlugin']
   > Cannot add task 'clean' as a task with that name already exists.

我试图删除第一行,但出现了新错误

A problem occurred evaluating project ':app'.
> Could not find method android() for arguments [build_epi4gcthpuruce7js1p17xxvs$_run_closure1@5c2243f6] on project ':app' of type org.gradle.api.Project.

这是完整的build.gradle(app)文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "com.example.nh.customlistviewexample"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.13.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
}

build.gradle 模块文件

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }

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

标签: androidgradleandroid-gradle-pluginbuild.gradlegradle-plugin

解决方案


推荐阅读