AGP 7.2.x jacoco coverage data is unexpectedly low

Viewed 129

Starting with AGP 7.2.0-alpha01 and onwards (including 7.2.0, 7.3.x, and 7.4.x preview builds), jacoco coverage is not working correctly despite all config/information seemingly being setup/working as expected.

On AGP 7.1.3, coverage shows up to the expected %s (very high for my app I am using - above 90% lets say) - things are healthy. When I switch to any newer AGP version, coverage drops to nearly something like 10% or less. Some coverage data does show up, but most of the classes in the app show as uncovered. I don't see a pattern for why some data shows up but some does not. Classes tested only via instrumentation tests and other classes tested only via regular unit tests both have data missing - and the opposite exists too (meaning the data shows up for a small number of classes in these cases), so it's very confusing...

I setup my jacoco task like so:

task developDebugCodeCoverageReport(type: JacocoReport, dependsOn: ['testDevelopDebugUnitTest', 'createDevelopDebugCoverageReport']) {
    group = 'Code Coverage'

    description = 'Generate Jacoco coverage reports for the developDebug build'

    reports {
        html.required.set(true)
        xml.required.set(true)
    }

    def excludes = [
        // list of files I want to exclude
    ]

    def javaClasses = fileTree(dir: "${buildDir}/intermediates/javac/developDebug/classes", excludes: excludes)
    def kotlinClasses = fileTree(dir: "${buildDir}/tmp/kotlin-classes/developDebug", excludes: excludes)
    classDirectories.setFrom(files([
            javaClasses,
            kotlinClasses
    ]))

    sourceDirectories.setFrom("${project.projectDir}/src/main/java")

    def junitTestsData = "${buildDir}/outputs/unit_test_code_coverage/developDebugUnitTest/testDevelopDebugUnitTest.exec"
    def androidTestsData = fileTree(dir: "${buildDir}/outputs/code_coverage/developDebugAndroidTest/connected/", includes: ["**/*.ec"])
    executionData.setFrom(files([
            junitTestsData,
            androidTestsData
    ]))
}

I assume AGP 7.2.x made some sort of change that broke how jacoco is able to read the coverage data. The exec and ec files that are generated are different sizes after updating the AGP version... but I don't know enough about jacoco/AGP configs to continue on my own.

I'm trying to setup a small sample app that demonstrates the issue, I fear it's a related complexity with one of the dependencies I am using, but we'll see... in the meantime - anyone have any thoughts?

1 Answers

I also encountered this problem. Is there any new output?

Related