Setting up an unified coverage report in Android with Jacoco, Robolectric, and Espresso
Rafael Toledo
32727

For info, after updating to the Android Gradle plugin 3.0.0, the jacocoTestReport task was failing to read the instrumentation test coverage report. I saw this error:

Unable to read execution data file /path/to/project/app/build/outputs/code-coverage/connected/Nexus_9_API_26(AVD) - 8.0.0-coverage.ec
...
org.jacoco.core.data.IncompatibleExecDataVersionException: Cannot read execution data version 0x1006. This version of JaCoCo uses execution data version 0x1007.

The solution I found (after several painful hours of trying different things) was to force using an older version of jacoco as follows:

If I tried to force using a newer version (0.7.8 for example), I saw this error in the emulator’s logcat:

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_773e439/Offline;

Gradle output this error:

No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).

I didn’t find a solution for this problem, so for now I’m using the older jacoco version, which is enough to create the coverage report.