https://kotlinlang.org logo
Title
j

juliocbcotta

05/10/2023, 10:02 AM
anyone here was able to migrate to JDK 17 and keep kapt working on android projects? Related link
t

tapchicoma

05/10/2023, 1:24 PM
I would advice you to configure Gradle JDK toolchain:
kotlin.jvmToolchain(17)
j

juliocbcotta

05/10/2023, 1:26 PM
The problem is that AGP 8.0 requires JDK 17, setting jvmToolChain 17, forces the bytecode to not be compatible with Android.
t

tapchicoma

05/10/2023, 1:27 PM
you mean running AGP 8.0 requires JDK 17?
j

juliocbcotta

05/10/2023, 1:27 PM
Yes, but the bytecode should be compatible with Java 8/11
t

tapchicoma

05/10/2023, 1:28 PM
then use
kotlin.jvmToolchain(8)
while running Gradle build on JDK 17
j

juliocbcotta

05/10/2023, 1:32 PM
With that the problem now is that, I will need to have JDK 17 and JDK 8/11 installed in the dev machine and CI server.
as stated in the stackoverflow thread.... Kotlin should not bind the bytecode compatibility with the jvmToolChain
t

tapchicoma

05/11/2023, 7:22 AM
Gradle should autoprovision missing JDKs required for build. If you really don't want to use toolchain - you could just configure Kotlin jvm target:
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile>().configureEach {
    compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8)
}
t

trevjones

05/25/2023, 10:55 PM
Yes, but the bytecode should be compatible with Java 8/11
That seems wrong to me. We have everything pointed at JDK17 and its been fine. D8/R8 seem to handle it fine. We also have library desugaring via
# <https://developer.android.com/studio/write/java8-support#library-desugaring-versions>
desugar-jdk = { group = "com.android.tools", name = "desugar_jdk_libs", version = "2.0.3" }