ajc
ajc

Reputation: 1725

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

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

Upvotes: 12

Views: 7027

Answers (7)

tnJed
tnJed

Reputation: 917

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.

Upvotes: 1

vicky
vicky

Reputation: 432

Try this one Procedure :-

1.right click on project ->Open Module Settings or F4

2.then goto SDK Location

3.after that Check on use embedded jdk(recommended)

you can see image given below

enter image description here

build and run project.

You can also add this in your build.gradle file

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Upvotes: 0

Nazim ch
Nazim ch

Reputation: 854

I think path has not been set as enviorment variable.

check have you declared the java sdk path . set the path as environment variable.

type "javac" in cmd(cmd must have admin previlliage).

If compile is not successfful

1 . Open the jdk location and copy the path of "bin"

2 . Open system properties in control panel.

3 . Advanced system settings -> then select "environment variables"

4 . click on "new"

5 . set variable name as "path" and variable value copied address

then try again

Upvotes: 2

Chaitanya Atkuri
Chaitanya Atkuri

Reputation: 1672

Try removing these two lines of code from your build.gradle

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

and

testCompile 'junit:junit:4.12'

Upvotes: 0

Akhil
Akhil

Reputation: 22

check if more than one jdk is installed.

Upvotes: -1

Kevin Brotcke
Kevin Brotcke

Reputation: 3973

This means the Java plugin is being applied on top of the Android plugin. I don't see anything that stands out in your build files though. Some things to try:

  • Try doing a clean build from command-line. That will tell you if it's an Android Studio problem.
  • Create an empty app from a clean slate and see if it builds.
  • Update Android SDK to latest
  • Update Android Studio to the latest
  • Remove Android Studio project files and re-import
  • Make sure correct Java version is in your path and JAVA_HOME is set correctly
  • Check if there is any jars in your local lib folder that could be conflicting
  • Try using beta version of Android plugin compile 'com.android.tools.build:gradle:2.3.0-beta2'

Upvotes: 1

Doron Yakovlev Golani
Doron Yakovlev Golani

Reputation: 5470

Not sure if this would help, but maybe you can try to explicitly add the java compilation option:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

Upvotes: 0

Related Questions