0

I am trying to update my android project to gradle 8.0. Which also requires an update to jdk 17.

Here is what I think the relevant parts in my build file:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}
kotlin {
    jvmToolchain(17)
}
kotlinOptions {
    jvmTarget = "17"
}

gradle wrapper:

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

Top level gradle file:

plugins {
    id 'com.android.application' version '8.0.0' apply false
    id 'com.android.library' version '8.0.0' apply false
...
}

When I build I am getting the following error:

Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)

Viewing other posts I have found its a possible bug with a workaround:

tasks.withType<KaptGenerateStubsTask>().configureEach {
    kotlinOptions.jvmTarget = libs.versions.java.bytecode.version.get()
}

However according to this answer: How to configure kapt to generate Java17 Java stubs in Android Gradle build file

You can just use:

kotlin {
    jvmToolchain(17)
}

Anyone using gradle 8.0 and jdk 17 successfully? If so any ideas?

lostintranslation
  • 23,756
  • 50
  • 159
  • 262
  • Have you checked that AndroidStudio also uses JDK17 for executing Gradle? If you have upgraded Android Studio then an older JDK may be configured by default. Such problems are pretty common with the latest Flamingo update, see e.g. https://stackoverflow.com/q/76137431/150978 – Robert May 05 '23 at 16:37
  • I am on Flamingo, which is using 17. I have also seen that I may need to drop to java 11 for this to work as there is a bug. – lostintranslation May 05 '23 at 16:39

0 Answers0