Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android jacoco coverage empty with gradle

I'm trying to make jacoco create a code coverage report for my android test project. I have the following in build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'jacoco'
...
jacoco {
    toolVersion = "0.7.1.201405082137"
}
...
android {
    buildTypes {
        release {
        }
        debug {
            testCoverageEnabled true
        }
    }
}

when I run gradlew -i createDebugCoverageReport, I get a coverage report, but it's empty. the end of the gradle execution is as follows:

:androidTest:connectedAndroidTest (Thread[main,5,main]) completed. Took 2 mins 36.951 secs.
:androidTest:createDebugCoverageReport (Thread[main,5,main]) started.
:androidTest:createDebugCoverageReport
Executing task ':androidTest:createDebugCoverageReport' (up-to-date check took 0.006 secs) due to:
  Output file /home/akos/src/androidTest/build/outputs/reports/coverage/debug has changed.
  Output file /home/akos/src/androidTest/build/outputs/reports/coverage/debug/index.html has been removed.
  Output file /home/akos/src/androidTest/build/outputs/reports/coverage/debug/.resources/package.gif has been removed.
[ant:reportWithJacoco] Loading execution data file /home/akos/src/androidTest/build/outputs/code-coverage/connected/coverage.ec
[ant:reportWithJacoco] Writing bundle 'debug' with 3 classes
:androidTest:createDebugCoverageReport (Thread[main,5,main]) completed. Took 0.215 secs.

BUILD SUCCESSFUL

Total time: 4 mins 53.467 secs

and indeed, the coverage.ec file referenced above is empty (of 0 length)

in the directory build/intermediates/coverage-instrumented-classes/ , I seem to have the instrumented class files

this is with gradle 2.1

what am I doing wrong?

like image 872
Ákos Maróy Avatar asked Nov 19 '14 00:11

Ákos Maróy


2 Answers

Try to generate the debug coverage report using Nexus device (5 or 5x), it will works perfectly. I was facing same issue with Samsung devices (coverage.ec is empty) but after that I run it with Nexus 5x and everything was working fine.

like image 63
naran z Avatar answered Sep 22 '22 10:09

naran z


There's a problem in the Android Gradle Plugin 0.14.0 that generates an empty coverage.ec file. It's known and was fixed in a branch but doesn't seem to have made it out to the public yet: https://code.google.com/p/android/issues/detail?id=78556

On the other hand, a lovely workaround template project for Android Studio can be found here using Jacoco and RoboElectric: https://github.com/nenick/android-gradle-template

So you can wait for Google to fix it or use someone else's build library repository, but Android Studio 1.0.0's gradle plugin is useless.

like image 20
confuzzled Avatar answered Sep 21 '22 10:09

confuzzled