Upgrade to AGP 4.2.0 ,unable to generate Jacoco code coverage report

1.9k Views Asked by At

Jacoco code coverage was working fine till I upgrade Android Gradle Plugin to 4.2.0 , no only app module code coverage getting generated, for modules it is not working. Any Idea how to fix this issue.

2

There are 2 best solutions below

1
On BEST ANSWER

I was having the same problem after upgrading to 4.2.1.

It looks like the Jacoco execution data file for non-instrumented unit tests has been renamed to 'jacoco.exec', and moved to the module's top-level directory.

In the configuration of my JacocoReport gradle task, this works for me:

executionData.from = "${project.projectDir}/jacoco.exec"

NOTE: The execution data file for instrumented tests has not been renamed or moved.

0
On

Based on amazing Richard answer, if you previously had this setup (which is pretty standard for unit and instrumented tests with Jacoco in Android)

executionData.from = fileTree(dir: project.buildDir, includes: [
  "jacoco/${testTaskName}.exec",
  "outputs/code_coverage/${variantName}AndroidTest/connected/**/*.ec"
])

You can switch to this equivalent for AGP 4.2.X

executionData.from = files([
  "$project.projectDir/jacoco.exec",
  fileTree(dir: project.buildDir, includes: [
    "outputs/code_coverage/${variantName}AndroidTest/connected/**/*.ec"
  ])
])