Skip to content
Advertisement

Gradle build: Java plugin not compatible with Android plugins

When I build, I have the error

The ‘java’ plugin has been applied, but it is not compatible with the Android plugins.

The internet answers says to remove the line “apply plugin: ‘java'” and the file gradle.init, but I can find neither in my environment… Where exactly is the java plugin applied, and how do I remove it?

My build.gradle looks like this:

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

plugins {
    id 'application'
}

apply plugin: 'com.android.application'
android {
    compileSdkVersion "28"
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'

        implementation 'com.google.guava:guava:30.1.1-jre'

    }


    application {
        mainClass = 'ProjectEmpireUnderworld.App'
    }

    tasks.named('test') {
        useJUnitPlatform()
    }
}

Advertisement

Answer

Please remove the following blocks from your build.gradle:-

application {
        mainClass = 'ProjectEmpireUnderworld.App'
    }

and

plugins {
    id 'application'
}

Both blocks are for java applications not for android apps. Please see this for more info on building APK

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement