Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Compile error: package com.sun.tools.javac is not exported by module jdk.compiler

ErrorModule jdk.compiler does not export com.sun.tools.javac.util

Short answer

JDK 17 and newer no longer allow code to reach JDK internals such as com.sun.tools.javac by default. The usual culprit is an old annotation processor or build tool. Update it first, run Gradle with a JDK it supports, and only then open the package with --add-exports.

  • Applies to JDK 17, 21 and 25, Gradle 8 and 9, Android Studio current stable
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out which JDK Gradle really runs on, and read the first line of the stack trace to see which tool touches javac.

    ./gradlew --version
  2. 2Match what you see, then jump to its fix

    1. 1The stack trace names a third-party class that calls com.sun.tools.javacAn old library, plugin or annotation processor uses JDK internalsFix
    2. 2The build worked before a JDK or Android Studio updateGradle runs on a newer JDK than the tool supportsFix
    3. 3Only one package is named in the error, and no newer tool existsYou cannot upgrade the tool, so the package must be openedFix

What does the error look like?

  • Module jdk.compiler does not export com.sun.tools.javac.util
  • java.lang.reflect.InaccessibleObjectException

Cause 1 of 3

An old library, plugin or annotation processor uses JDK internals

1Check

Identify the processor in the trace and look for a newer release that supports your JDK.

./gradlew assembleDebug --stacktrace

2Fix

Update that dependency or plugin to a version that does not rely on JDK internals.

# Raise the processor or plugin version in build.gradle(.kts) or the version catalog

3Verify

Run the build again.

./gradlew clean assembleDebug

Confirmed by docs.oracle.com

Did this fix it?

Cause 2 of 3

Gradle runs on a newer JDK than the tool supports

1Check

The JDK that runs Gradle in Android Studio is set in Gradle settings. In a terminal it is JAVA_HOME.

echo $JAVA_HOME
./gradlew --version

2Fix

In Settings > Build, Execution, Deployment > Build Tools > Gradle, pick a Gradle JDK that your tools support and keep JAVA_HOME the same.

# Android Studio: Settings > Build Tools > Gradle > Gradle JDK

3Verify

Sync Gradle and rebuild.

./gradlew --version

Confirmed by developer.android.com

Did this fix it?

Cause 3 of 3

You cannot upgrade the tool, so the package must be opened

1Check

Note the module and package in the message.

./gradlew assembleDebug --stacktrace

2Fix

Grant access to that one package with --add-exports. It works until the internal API changes, so treat it as a stopgap.

# Option form from the JDK migration guide; pass it to the JVM or compiler that fails
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

3Verify

The error is gone and the build passes.

./gradlew assembleDebug

Confirmed by docs.oracle.com

Did this fix it?

How do I stop it coming back?

  • Pin the JDK with a Java toolchain so every machine compiles with the same one.
  • Update annotation processors when you raise the JDK.
  • Check the Gradle and JDK compatibility table before upgrading either.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android app crashes because the Apache HTTP classes are missing

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;

From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.