首页 > 解决方案 > Gradle 同步失败:“java”插件已应用,但与 Android 插件不兼容。(8 秒 991 毫秒)

问题描述

当我更新 Android Studio 新版本时,我的意思是 5.1.1 gredle 给出了 Gradle 同步失败的一些错误:已应用“java”插件,但它与 Android 插件不兼容。(8 秒 991 毫秒)。请帮我。

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.beyza.myapplication"
        minSdkVersion 15
        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'
        }
    }
    sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/raw'] } }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    apply plugin: 'application'
    apply plugin: 'announce'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。

我不知道我该如何解决这个问题。

// 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.1'


        // 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
}```

标签: javaandroid

解决方案


从您的依赖项中删除“应用插件”并将其设置在 gradle 顶部,如下所示:

此外,如果您有“应用插件:'java'”,则将其删除。

apply plugin: 'application'
apply plugin: 'announce'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.beyza.myapplication"
        minSdkVersion 15
        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'
        }
    }
    sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/raw'] } }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

推荐阅读