Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 882
Dev Soni Avatar asked Jan 25 '23 09:01

Dev Soni


2 Answers

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.

like image 97
Richard Klein Avatar answered Jan 26 '23 22:01

Richard Klein


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"
  ])
])
like image 26
MatPag Avatar answered Jan 26 '23 23:01

MatPag