错误:已应用'java'插件,但它与Android插件不兼容。 AndroidStudio 3.0

时间:2017-11-04 10:39:05

标签: android gradle android-studio-3.0

我有这个gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.pavel.myapplication"
        minSdkVersion 16
        targetSdkVersion 26
        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'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

和这个gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

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


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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

这是新项目。创建此项目后我收到错误。使用此错误创建的新项目(!!!)

Error:(25, 0) Declaring custom 'clean' task when using the standard Gradle lifecycle plugins is not allowed.

我找到了this解决方案,并对此代码进行了评论

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

第一个错误消失但现在我得到了下一个错误。

Error:The 'java' plugin has been applied, but it is not compatible with the Android plugins.

我找到了删除'java'插件的解决方案,但我没有这个插件

1 个答案:

答案 0 :(得分:0)

我发现了问题。我有'java'插件的gradle.init文件。现在我不使用此配置并删除此文件。改变后一切正常!