I'm using games_services and it was working ok before updating Flutter to latest version.
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' (21).
Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain
Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation
build.gradles:
buildscript {
ext.kotlin_version = '1.9.23'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
games_services: ^4.0.1
Flutter (Channel stable, 3.19.2, on Microsoft Windows [Version 10.0.19045.4123], locale en-US) • Flutter version 3.19.2 on channel stable at C:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 7482962148 (10 days ago), 2024-02-27 16:51:22 -0500 • Engine revision 04817c99c9 • Dart version 3.3.0 • DevTools version 2.31.1
Solution You need to ensure that both the Java and Kotlin compilation targets are consistent. Try the following steps:
Update Kotlin JVM Target Ensure the Kotlin jvmTarget version matches the one set for Java (1.8):
Force JVM Compatibility Update the compileOptions to ensure both Java and Kotlin target the same version:
Use JVM Toolchain (Optional, if using Gradle 7.0+) Gradle 7+ introduced the concept of a JVM toolchain, which can help ensure consistent JVM versions across the project:
Consider Upgrading to a Higher JVM Target If you're using dependencies that require a higher JVM version (like Java 21), and your project supports it, you can update both Kotlin and Java to target the higher version: