skip to Main Content

I am using games_services package for my flutter app but I’m not able to run my app in android emulator, it returns following error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':games_services:compileDebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).

Here is my files settings:

android/build.gradle

buildscript {
    ext.kotlin_version = '1.9.23'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.4.1'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
    }
}


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

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

android/app/build.gradle

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

//....

compileOptions {
  sourceCompatibility JavaVersion.VERSION_1_8
  targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
  jvmTarget = '1.8'
}
//...

settings.gradle

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }

    plugins {
        id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version '8.3.1' apply false
}

include ":app"

gradle.properties

org.gradle.jvmargs=-Xmx4G
android.useAndroidX=true
android.enableJetifier=true

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-8.4-bin.zip

2

Answers


  1. Chosen as BEST ANSWER

    I've solved the issue by

    1. Removing android folder and re-create it. I don't know why that works but it did!

    2. Also you need to add

    id "org.jetbrains.kotlin.android" version "1.9.23" apply false
    

    In settings.gradle remember 1.9.23 is my version you change it to version you're using.


  2. update kotlin to 1.8.10
    and gradle to (android>gradle>wraper>gradlewraper.properties)
    distributionUrl=https://services.gradle.org/distributions/gradle-7.6-all.zip

    hope it helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search