Thanks to visit codestin.com
Credit goes to github.com

Skip to content

java.lang.NoClassDefFoundError | JaCoCo Offline Code Coverage | Gradle -Android #1163

@rajb865

Description

@rajb865

JaCoCo Tool Version - 0.8.6
Gradle Version - gradle-6.8.3
java Version - 11
Android Studio version - Android Studio Flamingo | 2022.2.1 Patch 2
Windows - Windows 10 (22H2)

I am using jacoco_offline.gradle file to generate the code coverage for an android project. When I run all of my test cases without JaCoCo, they are executing successfully. When I am running this ./gradlew createOfflineTestCoverageReport jacocoTestReport command in the root directory of my project, I am getting the below errors in all of my test cases

com.example.android.myproject.MyClassTest > test_updateProperties_Negative FAILED
    java.lang.NoClassDefFoundError at null:-1

in jacoco_offline.gradle file I see this block of code

gradle.taskGraph.whenReady { graph ->
    if (graph.hasTask(instrument)) {
        tasks.withType(Test) {
            doFirst {
                systemProperty 'jacoco-agent.destfile', buildDir.path + '/jacoco/testDebugUnitTest.exec'
                classpath = files(offline_instrumented_outputDir) + classpath + configurations.jacocoRuntime
            }
        }
    }
}

when I comment classpath = files(offline_instrumented_outputDir) + classpath + configurations.jacocoRuntime line in above code then my build works fine but I get the code coverage % as zero.

Could you suggest my if there is any problem with my configuration or it is a bug in JaCoCo offline code coverage?

Thanks,
Raj

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions