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

**URL:** <https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272>\
**Category:** Bugs\
**Tags:** issue-resolved, gradle-3498\
**Created:** [June 29, 2016, 6:08am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272 "2016-06-29T06:08:35Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![sreenivaskarthikeyan](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@sreenivaskarthikeyan](https://discuss.gradle.org/u/sreenivaskarthikeyan)\
**Post date:** [June 29, 2016, 6:08am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/1 "2016-06-29T06:08:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![martinn](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/martinn/32/5319_2.png) [@martinn](https://discuss.gradle.org/u/martinn)\
**Post date:** [June 29, 2016, 7:57am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/2 "2016-06-29T07:57:52Z")

</div>

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](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](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](https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin)

Cheers,  
Martin

---

<div class="post-metadata">

**Author:** ![sreenivaskarthikeyan](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@sreenivaskarthikeyan](https://discuss.gradle.org/u/sreenivaskarthikeyan)\
**Post date:** [June 29, 2016, 9:50am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/3 "2016-06-29T09:50:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Shorttail](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/shorttail/32/5333_2.png) [@Shorttail](https://discuss.gradle.org/u/Shorttail)\
**Post date:** [July 4, 2016, 3:10pm UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/4 "2016-07-04T15:10:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [July 8, 2016, 10:08am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/5 "2016-07-08T10:08:40Z")

</div>

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](https://issues.gradle.org/browse/GRADLE-3498) with 2.14 that makes it impossible to reconfigure the JacocoTaskExtension. Could you try with the latest nightly 2.14.1:

```groovy
./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!

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [July 8, 2016, 10:09am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/6 "2016-07-08T10:09:30Z")

</div>

Thank you for reporting!

There is a [bug](https://issues.gradle.org/browse/GRADLE-3498) with 2.14 that makes it impossible to reconfigure the JacocoTaskExtension. Could you try with the latest nightly 2.14.1:

```groovy
./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!

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [July 8, 2016, 10:51am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/7 "2016-07-08T10:51:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Shorttail](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/shorttail/32/5333_2.png) [@Shorttail](https://discuss.gradle.org/u/Shorttail)\
**Post date:** [July 9, 2016, 1:29pm UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/8 "2016-07-09T13:29:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sreenivaskarthikeyan](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@sreenivaskarthikeyan](https://discuss.gradle.org/u/sreenivaskarthikeyan)\
**Post date:** [August 17, 2016, 9:41am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/9 "2016-08-17T09:41:38Z")

</div>

> [@sreenivaskarthikeyan](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [August 18, 2016, 8:27am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/10 "2016-08-18T08:27:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sreenivaskarthikeyan](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@sreenivaskarthikeyan](https://discuss.gradle.org/u/sreenivaskarthikeyan)\
**Post date:** [August 18, 2016, 9:35am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/11 "2016-08-18T09:35:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [August 18, 2016, 1:08pm UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/12 "2016-08-18T13:08:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AamirAbro](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/aamirabro/32/5476_2.png) [@AamirAbro](https://discuss.gradle.org/u/AamirAbro)\
**Post date:** [August 24, 2016, 8:56am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/13 "2016-08-24T08:56:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [August 24, 2016, 8:18pm UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/14 "2016-08-24T20:18:42Z")

</div>

Hi Aamir,

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

```gradle
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

---

<div class="post-metadata">

**Author:** ![AamirAbro](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/aamirabro/32/5476_2.png) [@AamirAbro](https://discuss.gradle.org/u/AamirAbro)\
**Post date:** [August 24, 2016, 9:34pm UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/15 "2016-08-24T21:34:17Z")

</div>

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](https://gist.githubusercontent.com/rafaeltoledo/521ca928290f0c41102b/raw/4e71b301588b1f0c3d727697ee9b1eee95a7695c/jacoco.groovy). 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.

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [August 25, 2016, 6:38am UTC](https://discuss.gradle.org/t/jacoco-coverage-for-android-test-cases-fails-in-gradle-version-2-13-and-2-14/18272/16 "2016-08-25T06:38:37Z")

</div>

Hi @AamirAbro,

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

Cheers,  
Stefan
