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.
Asked
Active
Viewed 1,793 times
2 Answers
7
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.

Richard Klein
- 86
- 3
-
I haven't noticed this, my jacoco.exec seems to still be in the same location (${buildDir}/jacoco/${variantName}UnitTest.exec). But I am running into the same problem as the OP. Did you have to make any other changes? – Bradleycorn Jun 21 '21 at 16:52
5
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"
])
])

MatPag
- 41,742
- 14
- 105
- 114