I have this error on flutter when running flutter run
:
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':google_api_headers:compileDebugKotlin'. > Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17). Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation
The problem is that I think it’s not coming from my code but from the package ‘google_api_headers’.
I absolutely try everything, i have all my dependencies and android, gradle version up to date.
Bellow the result of ./gradlew -v
------------------------------------------------------------
Gradle 8.9
------------------------------------------------------------
Build time: 2024-07-11 14:37:41 UTC
Revision: d536ef36a19186ccc596d8817123e5445f30fef8
Kotlin: 1.9.23
Groovy: 3.0.21
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
Launcher JVM: 22.0.1 (Oracle Corporation 22.0.1+8-16)
Daemon JVM: /Library/Java/JavaVirtualMachines/jdk-22.jdk/Contents/Home (no JDK specified, using current Java home)
OS: Mac OS X 14.6.1 aarch64
My JDK version is 17
enter image description here
Bellow 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
}()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.5.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.23" apply false
id "com.google.gms.google-services" version "4.3.8" apply false
}
include ":app"
Bellow build.gradle
allprojects {
repositories {
google()
mavenCentral()
// [required] flutter_background_geolocation
maven { url "${project(':flutter_background_geolocation').projectDir}/libs" }
maven { url 'https://developer.huawei.com/repo/' }
// [required] background_fetch
maven { url "${project(':background_fetch').projectDir}/libs" }
}
}
ext {
compileSdkVersion = 34 // or higher / as desired
targetSdkVersion = 34 // or higher / as desired
minSdkVersion = 23 // Required minimum
appCompatVersion = "1.4.2" // or higher / as desired
playServicesLocationVersion = "21.0.1" // or higher / as desired
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Below app/build.gradle
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id "com.google.gms.google-services" // Google Services plugin
}
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'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
namespace "com.mycompany.test"
compileSdkVersion 34
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}
defaultConfig {
applicationId "com.mycompany.test"
minSdkVersion 23
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
compileOptions {
// Flag to enable support for the new language APIs (for flutter_local_notification)
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget=JavaVersion.VERSION_1_8
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
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
minifyEnabled true
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.10"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
}
My pubspec is up to date too flutter pub upgrade --major-versions.