59

I'm getting this strange AccessError after implementing Firebase Database dependencies. I had Firebase Authentication and Firebase Analytics enabled before loading Firebase Database. I'm using it as described in the Firebase documentation, with Firebase BOM.

I really don't understand why there is a failure with my JDK compiler. It seems like all my Gradle versions are up to date.

Project gradle:

buildscript {
    ext {
        nav_version = "2.5.3"
        ext.kotlin_version = '1.9.0'
        view_model = "2.4.1"
    }
    
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }

    dependencies {
        classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
        classpath 'com.google.gms:google-services:4.4.0'
        classpath 'com.google.firebase:firebase-plugins:2.0.0'
        classpath 'com.android.tools.build:gradle:8.1.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
    }
}

plugins {
    id 'com.android.application' version '8.1.4' apply false
    id 'com.android.library' version '8.1.4' apply false
    id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
    id("com.google.gms.google-services") version "4.4.0" apply false
}

Module gradle:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id("com.google.gms.google-services") // Firebase
    id 'kotlin-kapt'//Navigation

}

android {
    namespace 'com.example.dine_aid'
    compileSdk 34

    defaultConfig {
        applicationId "com.example.dine_aid"
        minSdk 28
        targetSdk 34
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            def keystorePropertiesFile = rootProject.file("keystore.properties")
            def keystoreProperties = new Properties()
            keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

            buildConfigField "String", "API_TOKEN", keystoreProperties["API_TOKEN"]
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        dataBinding true
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.12.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.10.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.android.car.ui:car-ui-lib:2.5.1'
    implementation 'androidx.room:room-common:2.6.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.0"
    implementation "org.jetbrains.kotlin:kotlin-reflect:1.7.10"

    //Firebase
    implementation(platform("com.google.firebase:firebase-bom:32.6.0"))
    implementation("com.google.firebase:firebase-auth")
    implementation("com.google.firebase:firebase-analytics")
    implementation("com.google.firebase:firebase-database")
    //LocalDate
    implementation "org.threeten:threetenbp:1.5.1"
    //RecyclerView
    implementation("androidx.recyclerview:recyclerview:1.3.1")
    //ImageLoader Coil
    implementation("io.coil-kt:coil:2.2.2")
    //Retrofit
    implementation "com.squareup.retrofit2:retrofit:2.9.0"
    implementation "com.squareup.retrofit2:converter-moshi:2.9.0"
    implementation "com.squareup.moshi:moshi-kotlin:1.14.0"
    //Material
    implementation 'com.google.android.material:material:<version>'
    //Navigation
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    //Glide
    implementation 'com.github.bumptech.glide:glide:4.14.2'
    // Coil
    implementation "io.coil-kt:coil:2.2.2"
    // HTML parsing Jsoup
    implementation 'org.jsoup:jsoup:1.14.3'
    //Nested ScrollView
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}

apply plugin: 'kotlin-kapt'

gradle.properties:

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false

gradle-wrapper.properties:

#Fri Oct 06 14:30:46 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

and here is the whole Error:

java.lang.IllegalAccessError: superclass access check failed: class org.jetbrains.kotlin.kapt3.base.javac.KaptJavaCompiler (in unnamed module @0x52cfe3c1) 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 @0x52cfe3c1
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
    at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:524)
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:427)
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:421)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:714)
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:420)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
    at org.jetbrains.kotlin.kapt3.base.KaptContext.<init>(KaptContext.kt:55)
    at org.jetbrains.kotlin.kapt3.KaptContextForStubGeneration.<init>(KaptContextForStubGeneration.kt:38)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.contextForStubGeneration(Kapt3Extension.kt:295)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:174)
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:104)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:104)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:114)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:88)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:256)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:42)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:247)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:87)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:47)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:168)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:100)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:46)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:460)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:62)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:476)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:399)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileNonIncrementally(IncrementalCompilerRunner.kt:280)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:124)
    at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:636)
    at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:101)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1598)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:714)
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:598)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:844)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:721)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:720)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1583)

Errors were stored into /Users/az2k4/AndroidStudioProjects/Dine_aid/.gradle/kotlin/errors/errors-1702057165982.log

I've tried to fire up Kotlin version 1.9.21 with JDK version 17, but with exactly the same result. I've experimented with a few other combinations, earlier versions, and the latest versions. The error code remains the same, no matter what I change.

I really don't understand why this is happening after I loaded the database dependency from Firebase. Before this, everything worked fine. Any help would be greatly appreciated! Thanks a lot in advance.

Best regards, a-bytecode

2
  • 3
    For everybody who had the same issue, this problem was solved by updating my IDE to the newest version (Android Studio Hedgehog).
    – a-bytecode
    Commented Dec 18, 2023 at 21:04
  • 3
    This issue appears from time to time. Currently i have this problem with JDK 21 / gradle 8.2 / Kotlin 1.9.20. Changing to JDK 17 / gradle 8.5 / Kotlin 1.9.23 did not help And yes, i'm running hedgehog and also tried jellyfish and commandline Commented May 3, 2024 at 15:14

19 Answers 19

78

Seems it was fixed in Kotlin 1.9.21. Look here for details

https://youtrack.jetbrains.com/issue/KT-60507

You mentioned that you tried with Kotlin 1.9.21 but I had pretty similar error but in another test case and it's successful build now with Kotlin 1.9.23, Java17 & gradle 7.6. Give it one more try))

2
  • 1
    The accepted answer links to a bug ticket but does not actually specify how to upgrade Kotlin or Grade for those that are new to Android development. For the latter, it was impossible for me to upgrade to Gradle 8.2 without uninstalling/installing Ladybug from Koala. Commented Jan 18 at 22:18
  • You should also update kotlinCompilerExtensionVersion to match your Kotlin version. developer.android.com/jetpack/androidx/releases/…
    – Alex
    Commented Feb 19 at 12:27
35

After wasting so much time with every possible solution restarting the machine worked for me!

5
  • 38
    I love Android development
    – mikemols
    Commented Aug 5, 2024 at 7:04
  • 7
    After updating Android Studio to the latest version, which comes with jdk 21 as the default, I encountered a compatibility problem and then this error when using jdk 17 (same as it was before). I tried multiple things and restarting the machine was what resolved the issue. I'm not sure why, but it saved the day for me. Thank you
    – Gigi
    Commented Oct 8, 2024 at 9:55
  • This worked for me as well! I'm also in the same boat of using a newer version of Android Studio that comes with jdk 21 but pointing it to a jdk 17 install.
    – Ben Baron
    Commented Nov 20, 2024 at 21:15
  • 3
    YOU SAVED ME AFTER 6HRS OF DEBUGGING GOOD SIR
    – GeraldTDPI
    Commented Dec 4, 2024 at 16:53
  • 1
    It really helped after updating Kotlin to version 20 and setting up JDK 17 for it.
    – CalmPerson
    Commented Dec 20, 2024 at 16:40
34

After wasting the whole day I tried updating the Kotlin version and it worked for me

  1. Updated Kotlin 1.9.20 to Kotlin 1.9.21
    // in build.gradle
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.21"

    // in app/build.gradle
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.21'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.21"
  1. Build > Clean Project

  2. And Run▶️

1
  • Thank you. now my project is also fixed using your solution. Commented Apr 13 at 19:46
13

Try following steps

Make sure you have the right Java version required for your project. If not set it.

Run java --version in your terminal to check.

Run jps in your terminal to get the process ids of KotlinCompileDaemon and GradleDaemon process. Kill all KotlinCompileDaemon and GradleDaemon process using

Kill -9 <processId>

Then try building it,

gradle clean build

2
  • 2
    Thank you for the hint. pkill -9 java and pkill -9 gradle can also work. if it does not work after kill it might be better to do File > Invalidate caches. Commented Oct 15, 2024 at 5:06
  • Thanks a lot! I was having the same problem. This error started happening right after I installed a new java version. Commented Mar 27 at 20:31
13

For those who didn't change anything regarding configuration on the project or machine, it's most likely an issue with multiple Kotlin Daemons running.

For me, the solution was to stop those daemons running. A simple way is from a Gradle-based project in the command line to run the following (macOS), but I think it's pretty much the same for Linux.

./gradlew --stop
1
  • This worked for me, no need to restart the machine.
    – JDdev
    Commented Feb 7 at 11:15
3

Here is my error message:

superclass access check failed: class org.jetbrains.kotlin.kapt3.base.javac.KaptJavaCompiler (in unnamed module @0x131f42e1) 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 @0x131f42e1

I found out that android team abandoned the kapt and want us to migrate to the ksp. This all happened after I updated my android studio to Ladybug | 2024.2.1.

So just migrate to the Ksp. You can find more information about the migration here.

1
  • Same, checking workaround...
    – AlexS
    Commented Mar 18 at 20:39
1

For some if you are updating the latest android studio ladybug Patch 2 and getting this kind of similar issue, Try using these steps

  1. Check Java version selected in Build, Execution, Deployment > Build Tools > Gradle

Update the java version, which you defined in your build.gradle, By default in latest update it selects jdk 21, update it to your desired one.

  1. Use ./gradlew --stop

  2. Clean or Invalidate and restart

1

I finally figured it out .

Update JAVA VERSION to 21

compileOptions {
    sourceCompatibility JavaVersion.VERSION_21
    targetCompatibility JavaVersion.VERSION_21
}
kotlinOptions {
    jvmTarget = '21'
}
composeOptions {
    kotlinCompilerExtensionVersion 1.5.15
}
id 'org.jetbrains.kotlin.android' version 1.9.22 apply false
id 'org.jetbrains.kotlin.jvm' version 1.9.22 apply false
0
updating all this to latest version worked for me.
agp = "8.7.2"
kotlin = "1.9.24"
coreKtx = "1.15.0"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
appcompat = "1.7.0"
material = "1.12.0"
activity = "1.9.3"
constraintlayout = "2.2.0"
gridlayout = "1.0.0"

and updating the AGP version to latest.

List item
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Nov 24, 2024 at 5:29
0

I had the same error when I tried adding Hilt to my project.

It worked after updating the version of Hilt, Kotlin, and upgrading to the latest Android Gradle Plugin.

0

After updating to Android Studio Ladybug | 2024.2.1 Patch 3, i have also face this problem After updating my kotlin = "1.9.0" to kotlin = "1.9.24" the issue was resolved for me i am using agp = "8.4.2" , gradle-8.6 and JDK-17

0

For me,

Adding this in gradle.properties fixed the issue!

org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" --add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --illegal-access=permit

--illegal-access=permit - This option allows illegal reflective access but is deprecated and will be removed in future JDK versions.

0

after trying almost everything shown in this thread, I got it working by updating Android Studio. Go to Help > Check for updates. When updating, this window appeared:

some conflicts were found

theese are procceses locked by the JDK and this suggests to kill the proccesses (right column). Restarting my computer and trying ./gradlew --stop didn't work for me. I clicked proceed and everything worked fine afterwards.

-1

Following worked for me. Open the build.gradle file in the root folder of your project. Update the version of

androidx.navigation.safeargs

to 2.8.2 (latest at this time)

After above change, the error was gone.

-1

The likely reason is a mismatch in the JDK version.

You can try the following (on Mac system):

  1. You can determine the JDK version by using the following command;

    java -version

  2. Open the terminal and execute the following commands;

    /usr/libexec/java_home -V

  3. Try lowering the JDK version;

    • open ~/.bash_profile
    • And add [export JAVA_HOME=`/usr/libexec/java_home -v 17.0.10]
    • source .~/.bash_profile

PS: You may also need to pay attention to the Gradle version。

./gradlew --v
-1

I'm getting this on multiple old projects after upgrading to JDK 21 with AS Ladybug.

The route issue for me seems to come from the navigation kapt code:

classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0'

And upgrading to 2.5.3 resolves it (also ensure to use 2.5.3 for the other navigation dependencies). I also updated some other things before that:

  • com.google.dagger.hilt.android plugin: 2.44 -> 2.49
  • gradle wrapper: 8.7 -> 8.9
  • android gradle plugin: 8.5.2 -> 8.7.1
  • kotlin gradle plugin: 1.9.10 -> 1.9.23

But I'm pretty sure that version of navigation and JDK 21 are the issue.

-1

In my case I switched from (app level gradle)

implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.23"

to

implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.21"

and there were some min sdk issues so I had to shift from 21 to 23 (app level gradel)

minimumSdkVersion = 23

After that I update (root level gradle)

classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.7.7")

to

classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.8.2")

-1

Preferred Scenario: Issue with Android Studio after updating to the Ladybug version. with Existing projects

migrating kotlin to 2.0.0

  • If we use kotlin = "2.0.0" need to update agp to "8.7.2" fixed

  • Also If you are using Jetpack Compose and Kotlin 2.0.0 or above, we need to add a Compose compiler for the project while migrating to Kotlin 2.0.0

    plugins { id("org.jetbrains.kotlin.plugin.compose") version "2.0.0" }

  • Gradle wrapper needs to update 8.9 in gradle-wrapper.properties file

1
  • 1
    Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation? Commented Nov 30, 2024 at 1:32
-1

Worked in my case, you can try out below steps

-

Try 1

Go to gradle.properties and add the below line, and all set!

org.gradle.jvmargs=--add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED

Try 2

If above code didn't worked for you then try adding below statement in gradle.properties

org.gradle.jvmargs=--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED \
--add-opens=java.base/java.lang=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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.