First I added apply plugin: 'jacoco' in my gradle file.
Next, I activated unit test coverage in my gradle file by setting enableUnitTestCoverage to true:
buildTypes {
debug {
applicationIdSuffix ".debug"
signingConfig signingConfigs.debug
enableUnitTestCoverage true
}
}
I ran the gradle task createDebugUnitTestCoverageReport using the gradle wrapper with this command: ./gradlew clean createDebugUnitTestCoverageReport
The code coverage report is generated but coverage percentage is always 0 whereas I have unit tests and when I run "Tests with coverage" in Android Studio my code coverage is not 0.
I use Android Gradle Plugin 7.4.2 (com.android.tools.build:gradle:7.4.2), Gradle 7.5 and Java 11. I use gradle with Groovy.
Do you know how can I fix this issue?
Thanks for your help
Upgrading to Android Gradle Plugin 8.0.0 solved my issue. Maybe there is a bug with the version 7.4.2.
Keep in mind that AGP 8.0.0 requires java 17.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With