Elen Mouradian
Elen Mouradian

Reputation: 665

java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector cannot access class com.sun.tools.javac.code.Symbol$

I'm trying to build the application with Java SE 11 and Gradle 7.0, and it builds using the IDE however when I try to build it using the terminal I get this error. How can I fix it.

java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x1d7a8227) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x1d7a8227

Upvotes: 40

Views: 59608

Answers (12)

Francis Bacon
Francis Bacon

Reputation: 4785

Android Studio Iguana | 2023.2.1 Build #AI-232.10227.8.2321.11479570, built on February 22, 2024 Runtime version: 17.0.9+0-17.0.9b1087.7-11185874 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 14.4.1 GC: G1 Young Generation, G1 Old Generation Memory: 4096M Cores: 12 Metal Rendering is ON

By default, this version of Android Studio is using JDK17.

Settings -> Build, Execution, Deployment -> Build Tools > Gradle -> Gradle JDK is GRADLE_LOCAL_JAVA_HOME (GRADLE_LOCAL_JAVA_HOME JetBrains Runtime version 17.0.9 /Applications/Android Studio.app/Contents/jbr/Contents/Home)

Solution: Change it to JDK11.

Upvotes: 0

user9311386
user9311386

Reputation: 1

works for me by updating compile and testCompile to implementation and testImplementation, and upgrade gradle to 7.+

Upvotes: 0

Prince Vora
Prince Vora

Reputation: 46

for flutter run this command may be your issue resolve

rm -r ~/.pub-cache
rm -r ./pubspec.lock
flutter clean
flutter pub get
flutter pub cache clean
flutter pub cache repair
flutter precache
dart pub upgrade
flutter pub run build_runner build --delete-conflicting-outputs

Upvotes: 1

Shirish Singh
Shirish Singh

Reputation: 857

You need to downgrade your java version to JDK 11 version. For Mac OS Users Follow below Steps:

  1. Check the Java version's already installed and see if jdk11 is installed or not, if not, install it first.

/usr/libexec/java_home -V

  1. Open vim ~/.zshrc
  2. Add the below line , note update your JDK name properly below

export JAVA_HOME=/Library/Java/JavaVirtualMachines/<<Your_JDK_11_version>>/Contents/Home

  1. Restart the terminal
  2. Check Java Version

java -version

Upvotes: 3

Jayesh
Jayesh

Reputation: 111

I used jdk 11.0.13 version and it works well.

This is my ~/.bash_profile

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home

Upvotes: 1

Bijay Jena
Bijay Jena

Reputation: 31

I had to upgrade my gradle file to 7.3.1 and add this line in gradle.properties in android directory org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED

The gradle upgrade is required for Java 17 support

Upvotes: 3

Raphael Torres
Raphael Torres

Reputation: 121

I resolved upgrading the gradle version with this:

./gradlew wrapper --gradle-version 7.5

Upvotes: 12

Doan Bui
Doan Bui

Reputation: 4446

It took me up to 3 working days and I found a simple solution. Go to android/gradle.properties change org.gradle.jvmargs=-Xmx1536M to

org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED

Upvotes: 48

Manoj
Manoj

Reputation: 442

Downgrading from open jdk 17 to 11 worked for me.

Upvotes: 40

S34N
S34N

Reputation: 8371

Resolved it by recreating the project from existing sources & updating the .gradle-wrapper.properties version to 7.3.2

Location: gradle/wrapper/gradle-wrapper.properties

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

Upvotes: 18

Pedro
Pedro

Reputation: 133

I encountered the same error. To get around it, I ended up setting the JAVA_HOME environment variable before running gradle from the command line, and also added it to my path.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home 
export PATH=$JAVA_HOME/bin:$PATH

openjdk-11 worked fine for me, but you want to make sure your JAVA_HOME environment variable points to an actual location before setting it. This may vary based on your OS.

Upvotes: 3

Nayara Dias
Nayara Dias

Reputation: 1

I am having the same issue. When I was running in intellij terminal ./gradlew build war this exception happened.

I saw the problem is terminal java version. In terminal is 17 and my application is running in 11.

I solve my problem creating war file by intellij, but there is some missing environment configuration to fix in my terminal.

Upvotes: 0

Related Questions