'kaptGenerateStubsDebugKotlin fails on a Apple M1 Macbook (JDK 11)
I get this failure both in Android Studio and running ./gradlew assembleDebug
on the command line on a new Macbook with Apple M1 Max chip. On my old Intel Mac there are no problems building the project.
> Task :app:kaptGenerateStubsDebugKotlin FAILED
e: java.lang.IllegalAccessError: class org.jetbrains.kotlin.kapt3.base.KaptContext (in unnamed module @0x4d1ecff7) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x4d1ecff7
at org.jetbrains.kotlin.kapt3.base.KaptContext.<init>(KaptContext.kt:28)
at org.jetbrains.kotlin.kapt3.KaptContextForStubGeneration.<init>(KaptContextForStubGeneration.kt:40)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.contextForStubGeneration(Kapt3Extension.kt:287)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:171)
at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:102)
(Here's the full error output)
class org.jetbrains.kotlin.kapt3.base.KaptContext (in unnamed module @0x4d1ecff7) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x4d1ecff7
Googling around, the error message looks a lot like the one here: "Kapt is not compatible with JDK 16+". But thing is, I'm using JDK 11. (Same result on both Android Studio's default JDK (11.0.10) and "11.0.13 2021-10-19 LTS" downloaded from www.oracle.com.)
Any ideas how to get this working on the M1 Mac?
Solution 1:[1]
From the link mcomella has shared - https://youtrack.jetbrains.com/issue/KT-45545, they have fixed it in Kotlin 1.6.x.
So bumping to Kotlin 1.6.x has worked for my case (Apple M1 Pro).
Solution 2:[2]
I solve it in my MacBook Air M1 updating the Kotlin version and all other library for the last version, you have to update the compileSDKVersion and targetSDKVersion for the latest version as well.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Wei Yuan |
Solution 2 | Desilio do Carmo Lima Neto |