JaCoCo class mismatch when running together with Firebase Perf plugin
See original GitHub issueHi @Rolf-Smit, after trying to upgrade the root coverage plugin 1.5.1 it works perfectly. But after I check again the report, one of unit test inside the app module isn’t covered but the other modules are covered correctly. When I run the command I have an error like this
[ant:jacocoReport] Classes in bundle 'My App' do not match with execution data. For report generation the same class files must be used as at runtime.
[ant:jacocoReport] Execution data for class com/example/myapp/presentation/viewmodel/SplashScreenViewModel does not match.
Here’s the report
For your information,
- I was already set
testCoverageEnabled
as true and running the command at the correct build type - I was already searching this issue at stackoverflow, and the cause is about a different JAVA version or using a different Gradle. The question is, It’s okay if compileOptions in my project is different from the actual java version I used? Because, I’ve used this setup (compileOptions and java version) before, and running well.
- I was already upgraded and downgraded the jacoco too, from existing 0.8.6 > 0.8.7 > 0.8.8 but still not covered.
My Version
- AGP:
7.2.0
- Root Coverage:
1.5.1
- Kotlin Gradle:
1.6.21
- Jacoco:
0.8.6
- Java Version:
11.0.9
- Compile Options:
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Firebase Perf Instrumentation breaks JaCoCo reporting #3948
When applying the Firebase Performance plugin to a module, JaCoCo test coverage reports break and show 5) coverage for everything in that ...
Read more >AGP 4.2 breaks JaCoCo coverage reports [191774966]
When running the jacoco coverage report, All classes will report 0% ... It seems that having the Firebase Performance Monitoring plugin ...
Read more >Execution data for class does not match + Jacoco
Although now I'm trying to run multiple junit tests together to find their coverage. I've been able to run all junit tests within...
Read more >Get started with Performance Monitoring for Android - Firebase
The Performance Monitoring Gradle plugin v1.1.0 can cause a mismatch in Guava dependencies, resulting in the following error: Error:Execution failed for task ...
Read more >Android Studio 2021.1.1 Closed Issues
Android Gradle Plugin 7.0.2 crashes app on Android 4 and 5 devices with Verifier rejected class due to bad method ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@MirzaUkas thanks, this is helpful.
So what’s happening is that both JaCoCO and Firebase Performance manipulate and rewrite your class files. JaCoCo does this to add code so that it can measure which lines have been “visited” during a test. Firebase Performance does this so it can add code to measure performance.
The issue is that for JaCoCo to work the class files used at runtime must be exactly the same class files that are given to JaCoCo (otherwise coverage data does not match up). This plugin uses the official Android Gradle Plugin APIs to provide those class files to JaCoCo. It seems to be the case that JaCoCo (and this Plugin) is provided with class files that do not contain the Firebase Performance changes, while at runtime those changes are in the code, this creates a mismatch between runtime and the class files available for calculating the coverage.
Where does this need fixing? To be honest I’m also not too sure, since there could be multiple things at play here. Maybe the ordering in which the Firebase Performance plugin is applied and JaCoCo (this plugin) could make a difference. Maybe you could move them around and make sure JaCoCo is the last one applied? Or maybe first one?
You could do this by using (or maybe just changing the order in the plugins block already make a difference):
But a quick fix that is guaranteed to work would be to not enable Firebase Performance while running tests in the first place. Firebase Performance is a tool to monitor performance issues on production and to my knowledge it is often disabled on debug (test) builds because it is not needed there, but more importantly when disabled it also has a positive impact on compile times.
Here is some documentation on how you can disable it for specific build-types: https://firebase.google.com/docs/perf-mon/disable-sdk?platform=android#disable-gradle-plugin
@Rolf-Smit, after trying to check my plugin my first suspicious plugin that cause this problem is firebase crashlytic because this plugin is crash reporting plugin like you asked before. But after trying to comment this plugin, the test is still uncovered. Interestingly, after trying to comment and uncomment another ‘suspicious’ dependencies. I found that when I comment firebase performance dependencies the test is covered and the issue is gone. I don’t know which plugin must solve this issue, the firebase perf, jacoco, or root coverage plugin.
This is my dependencies on my
build.gradle
projectcom.google.gms:google-services:4.3.3
org.jacoco:org.jacoco.core:0.8.6
com.github.triplet.gradle:play-publisher:3.7.0
com.github.ben-manes:gradle-versions-plugin:0.39.0
nl.neotech.plugin:android-root-coverage-plugin:1.5.1
com.google.firebase:firebase-crashlytics-gradle:17.0.1
com.google.firebase:firebase-appdistribution-gradle:2.0.0
com.google.firebase:perf-plugin:1.4.1