close

[Solved] Cannot run gradle test tasks because of java.lang.NoClassDefFoundError: jdk/internal/reflect/GeneratedSerializationConstructorAccessor1

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing the following error Cannot run gradle test tasks because of java.lang.NoClassDefFoundError: jdk/internal/reflect/GeneratedSerializationConstructorAccessor1 in Java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Cannot run gradle test tasks because of java.lang.NoClassDefFoundError: jdk/internal/reflect/GeneratedSerializationConstructorAccessor1 Error Occurs?

Today I am facing the following error Cannot run gradle test tasks because of java.lang.NoClassDefFoundError: jdk/internal/reflect/GeneratedSerializationConstructorAccessor1 in Java.

How To Solve Cannot run gradle test tasks because of java.lang.NoClassDefFoundError: jdk/internal/reflect/GeneratedSerializationConstructorAccessor1 Error ?

  1. How To Solve Cannot run gradle test tasks because of java.lang.NoClassDefFoundError: jdk/internal/reflect/GeneratedSerializationConstructorAccessor1 Error ?

    To Solve Cannot run gradle test tasks because of java.lang.NoClassDefFoundError: jdk/internal/reflect/GeneratedSerializationConstructorAccessor1 Error This is an old issue, but for future google searchers and perhaps interested parties that could work around this, it is worth mentioning that if you are using one of the more popular walk-throughs to set up JaCoCo + Robolectric + Espresso

  2. Cannot run gradle test tasks because of java.lang.NoClassDefFoundError: jdk/internal/reflect/GeneratedSerializationConstructorAccessor1

    To Solve Cannot run gradle test tasks because of java.lang.NoClassDefFoundError: jdk/internal/reflect/GeneratedSerializationConstructorAccessor1 Error This is an old issue, but for future google searchers and perhaps interested parties that could work around this, it is worth mentioning that if you are using one of the more popular walk-throughs to set up JaCoCo + Robolectric + Espresso

Solution 1

This is an old issue, but for future google searchers and perhaps interested parties that could work around this, it is worth mentioning that if you are using one of the more popular walk-throughs to set up JaCoCo + Robolectric + Espresso – https://medium.com/@rafael_toledo/setting-up-an-unified-coverage-report-in-android-with-jacoco-robolectric-and-espresso-ffe239aaf3fa . Please add below this:

tasks.withType(Test) {
    jacoco.includeNoLocationClasses = true
    jacoco.excludes = ['jdk.internal.*']
}

In my case:

junitJacoco {
    jacocoVersion = '0.8.4' // type String
    includeInstrumentationCoverageInMergedReport = true // type boolean
    tasks.withType(Test) {
        jacoco.includeNoLocationClasses = true
        jacoco.excludes = ['jdk.internal.*']
    }
}

Solution 2

In such case, even if your JAVA_HOME is set in bash_profile, you also need to set in Android, to do so: Go to File -> Project Structure -> SDK location set JDK location.

At times, it might a different location from bash_profile one.

Refer to screenshot for reference 

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read