Jacoco coverage for android test cases fails in gradle version 2.13 and 2.14

Jacoco coverage for android test cases fails with error
Unable to read execution data file App/build/outputs/code-coverage/connected/coverage.ec

However it works well for junit test cases. (testUnitTest.exec)

This is happening only in gradle version 2.13 and 2.14.

Gradle Version: 2.13
Operating System: Ubuntu
Is this a regression? If yes, which version of Gradle do you know it last worked for? gradle version < 2.13

Hi,

this might be related to the change of the format of the exec file in JaCoCo 1.7.5:
http://www.eclemma.org/jacoco/trunk/doc/changes.html

JaCoCo was updated in Gradle 2.13, check the release notes for how to downgrade the version:
https://docs.gradle.org/2.13/release-notes.html#jacoco-version-upgrade-to-0.7.6

If you use Jenkins you have to use the right version of the JaCoCo plugin to make it work, details here:
https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin

Cheers,
Martin

Hi

Thanks. I’m able to avoid the above error with the default jacoco version.

But the coverage file is not proper with the gradle verions 2.13 and 2.14

The exec file size is 92K with gradle version 2.13 and 2.14 which is supposed to be around 1MB.
So i’m not getting the proper coverage with latest gradle verison.

The jacocoTestReport task does not seem to understand the new exec format. Is there a way to update that?

Thank you for reporting!

The jacocoTestReport task always uses the same version of Jacoco used for generating the exec file. So it should always be able to generate the test report. There is a bug with 2.14 that makes it impossible to reconfigure the JacocoTaskExtension. Could you try with the latest nightly 2.14.1:

./gradlew wrapper --gradle-version=2.14.1-20160708091932+0000

If you could provide a stacktrace or a link to an example project that would be great!

Thank you for reporting!

There is a bug with 2.14 that makes it impossible to reconfigure the JacocoTaskExtension. Could you try with the latest nightly 2.14.1:

./gradlew wrapper --gradle-version=2.14.1-20160708091932+0000

If you could provide a stacktrace or a link to an example project that would be great!

1 Like

I did test coverage with Android Studio, Gradle 2.14 and the Gradle Android plugin with version 2.1.2. For adding coverage add

android {
    buildTypes {
        debug {
            testCoverageEnabled = true
        }
    }
}

to your build.gradle. Note that you need to run createDebugCoverageReport to obtain the Jacoco test report.

This worked for me without any problems.

Thank you, I got it working. Changing the current Gradle version to 2.14.1-20160708091932+0000 and cleaning fixed the problem. <3

Edit: Disregard that. The bug in version 2.14 was not the cause of my trouble, it was simply a matter of cleaning the old exec file, which was never updated due to java files not having changed since the last run. The Jacoco version of the exec file and the report generator were the same all along. Sorry for the noise.

Even 2.14.1 has the same issue. Any update on this ?

Hi again,

it is strange that the exec file size is different for you. Does this mean that in the report you also don’t see the correct coverage? Could you provide an example project with which I can reproduce this problem?

You should also try Gradle 3.0 and the Android Gradle plugin 2.2.0-beta1.

Hi

I tried with Gradle 3.0 and the Android Gradle plugin 2.2.0-beta1. Still didn’t help.
Coverage is not proper.

Here is my observation

Any jacoco tool version and gradle version <= 2.12 - Coverage is proper

Any jacoco tool version and gradle version > 2.12 - Covergae is not proper.(exec file size is very small)

I tried to replicate in a sample project, but couldn’t.

As long as I can not reproduce this I am not able to analyze the problem - as soon as you can provide a sample project I will have a look. It seems like jacoco works for other users.

I have been facing same issue after upgrading to 2.14.1.

we have configured teamcity where coverage reports are generated from exec file using service message ##teamcity[jacocoReport dataPath=’’]

If I down grade to 2.12 it works.

Hi Aamir,

what is the same issue you are facing? Does your Jacoco coverage for Android fail with an error:

Unable to read execution data file App/build/outputs/code-coverage/connected/coverage.ec

Then this is the right forum post and I will need to investigate.
Is Teamcity unable to parse the Jacoco exec file or does it not find the exec file? Then this is a different error. Please open a new post for that.

Regards,
Stefan

hello @sradi,

It may not be the same issue but it seems related.

I am having trouble generating coverage reports for UNIT TESTs in android.
Team city coverage reports works fine on gradle version 2.12, but not when I upgrade to 2.14.1. May be teamcity is using old jacoco version?

But I can’t even generate local coverage report on my machine using some thing similar to this gradle task. This too works fine on 2.12. The report is generated but coverage is zero.

I tried it on android gradle plugin 2.2.0-beta2 and gradle version 3.0, same result on my local machine.

I see .exec file is being generated however size is small 42k in new versions (2.14.1 and 3.0) while it was around 230k in 2.12.

I guess I need to open a different thread. let me know if I do.

Hi @AamirAbro,

Please open a different thread. Providing a self contained example would really help.

Cheers,
Stefan