Skip to content

IllegalAccessError During Build with KAPT with newer Android Studio version #15

@pioLay

Description

@pioLay

When building the project, the following error occurs during tasks involving Kotlin's annotation processing (KAPT):

java.lang.IllegalAccessError: superclass access check failed: class org.jetbrains.kotlin.kapt3.base.javac.KaptJavaCompiler 
(in unnamed module @0x4a69b0f1) cannot access class com.sun.tools.javac.main.JavaCompiler 
(in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.main to unnamed module @0x4a69b0f1

This issue arises because the Java Development Kit (JDK) enforces stricter module access controls, preventing KAPT from accessing internal javac classes.


Steps to Reproduce

  • Clone the project.
  • Ensure the environment is using a JDK version >= 17. (on the latest branch it is already set to 18)
  • Run ./gradlew assembleDebug.

Solution

The issue was resolved by changing the following line to gradle.properties:

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 --add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

This JVM argument opens the required module for KAPT, allowing the build to proceed successfully.


Suggested Fix

Please add the above configuration to the gradle.properties file to ensure compatibility with JDK versions >= 17. This will prevent the error for developers using newer JDK versions.


Environment

Android Studio Ladybug | 2024.2.1 Patch 3 (Build #AI-242.23339.11.2421.12700392, built on November 22, 2024)
JDK Version: 17 or higher

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions