Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'java' plugin is not compatible with the Android plugins

I'm getting an error right after I installed Android studio and Created a simple app.

Steps followed:

  1. Fresh download & installed Android studio.
  2. Created a new project.

When the project loaded, The gradle failed with error:

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

Module Gradle File:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "info.ankitjc.happybirthday"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    testCompile 'junit:junit:4.12'
}

Project Gradle File:

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

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

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

allprojects {
    repositories {
        jcenter()
    }
}

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

I searched for possible solutions here.

  • Android compile error; Java plugin has been applied, not compatible with android
  • Gradle error "Java plugin is not compatible with android plugins"

After File > Invalidate Cache/Restart After File > Invalidate Cache/Restart

like image 948
ajc Avatar asked Jan 13 '17 19:01

ajc


1 Answers

I experienced this error while updating from KAPT to KSP. The docs say to add

id 'org.jetbrains.kotlin.jvm'

to the plugins block, but it appears that adding the Kotlin jvm plugin to the mix was causing my java plugin error. Remove the reference and it compiles. FYI the linked docs are more figurative than literal.

like image 156
tnJed Avatar answered Sep 17 '22 14:09

tnJed