Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17)

I´m building a flutter application in Android Studio and keep getting this error after installing a package when trying to build the application. This is the full error message:


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_image_compress_common:compileDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
  Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain


* Try:
> 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

As the error states that the current target is version 1.8, I tried to adjust the android/app/build.gradle file like this:

...
kotlin {
    jvmToolchain(17)
}

android {
    namespace 'de.dthinking.app'
    compileSdkVersion 34

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }
  ...
}

Executing ./gradlew --version has this output:

------------------------------------------------------------
Gradle 8.0
------------------------------------------------------------

Build time:   2023-02-13 13:15:21 UTC
Revision:     62ab9b7c7f884426cf79fbedcf07658b2dbe9e97

Kotlin:       1.8.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17 (Oracle Corporation 17+35-LTS-2724)
OS:           Windows 10 10.0 amd64

Other solutions adjusted the gradle settings, but they are not displayed in my case: android studio overlay

I got it to work by adjusting the android/build.gradle:

allprojects {
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions.jvmTarget = "1.8"
    }

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KaptGenerateStubs).configureEach {
        kotlinOptions.jvmTarget = "1.8"
    }
}

This does not work when I set the jvmTarget to "17", the same error from the beginning occurs. But I would like to use version 17 instead of 1.8. I would really appreciate an explanation as to why my changes to the android/app/build.gradle do effectively nothing. Are there any other files that need to be adjusted?

like image 613
Juli2813 Avatar asked Dec 07 '25 04:12

Juli2813


1 Answers

After a lot of trials, i got to understand that that it was a version problem, so I tried a lot of combinations of versions and codes, but this was what gave me result and my code started running again.

in

anddroid/buid.gradle

subprojects {
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
        kotlinOptions.jvmTarget = "1.8"
    }
}

more things i tried are these below

android {
    namespace = your project namespace value
    compileSdk = 34
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = '17'
    }

    kotlin {
        jvmToolchain(17)
    }
... more code here

on android/build.gradle

after

 allprojects {
.....
}

//here more solution in case you also have namespace or related issue, try this

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty('android')) {
            project.android {
                if (namespace == null) {
                    namespace project.group
                }
            }
        }
    }
}
// ends here
like image 179
Meshach Avatar answered Dec 09 '25 20:12

Meshach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!