Davis Fila
Davis Fila

Reputation: 15

Though the 'java' plugin has been installed, the Android plugins are incompatible with it

Please I have struggling with this error and yet I am not getting any solution FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

A problem occurred configuring project ':app'. The 'java' plugin has been applied, but it is not compatible with the Android plugins.

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. Get more help at https://help.gradle.org. ==============================================================================

2: Task failed with an exception.

A problem occurred configuring project ':app'. The 'java' plugin has been applied, but it is not compatible with the Android plugins.

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. Get more help at https://help.gradle.org. ==============================================================================

BUILD FAILED in 2s Error: Gradle task assembleDebug failed with exit code 1

Android/build.gradle

buildscript {
    ext.kotlin_version = '1.9.23' // Add this line for Kotlin
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.4.1'
        classpath 'com.google.code.gson:gson:2.10.1'
        classpath 'com.google.guava:guava:29.0-jre'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Add this line for Kotlin
        classpath 'com.google.code.findbugs:jsr305:3.0.2'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

app/build.gradle

plugins {
    id "com.android.application"
    id "kotlin"
    id 'kotlin-parcelize'
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services" 
    
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}



android {
    namespace "com.example.passco"
    compileSdk flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

    kotlinOptions {
        jvmTarget = '1.8'
        apiVersion = '1.1'
        languageVersion = '1.1'
    }
}

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    dexOptions {
    javaMaxHeapSize "4g"
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.passco"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    buildFeatures {
        viewBinding true
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }

    apply plugin: 'com.google.gms.google-services'
}

flutter {
    source '../..'
}

dependencies {
        // Import the Firebase BoM
    implementation(platform("com.google.firebase:firebase-bom:32.8.0"))

    // TODO: Add the dependencies for Firebase products you want to use
  // When using the BoM, don't specify versions in Firebase dependencies
    implementation("com.google.firebase:firebase-analytics")

    // Add the dependencies for any other desired Firebase products
  // https://firebase.google.com/docs/android/setup#available-libraries
    implementation 'com.android.support:multidex:1.0.3'
}

The internet is saying I should remove apply plugin: 'java' but I can't find it anywhere. Am i missing something? Please help.

Upvotes: 0

Views: 282

Answers (1)

Simon Jacobs
Simon Jacobs

Reputation: 6481

Your line

id "kotlin"

applies the Kotlin JVM plugin, and that plugin in turn applies the Java plugin.

To use Kotlin in an Android project, you instead need the Kotlin Android plugin, which you can apply by writing:

id 'kotlin-android'

Upvotes: 0

Related Questions