Use jacoco in android library Module


(Zhangzhen) #1

I write some JUnit test for an Android Library Module, then I wanna use jacoco plugin to get code coverage, my build.gradle like below:

apply plugin 'com.android.library'
apply plugin 'jacoco'
......
android{
buildTypes {
        debug {
            testCoverageEnabled true
        }
    }
}

tast coverageReport(type: 'JacocoReport'){
  executionData = files('build/jacoco/testDebugUnitTest.exec')
    sourceDirectories = files('src/main/java')
    classDirectories = fileTree(dir: 'build/intermediates/classes/debug',
            excludes: ['**/R.class',
                       '**/R$*.class',
                       '**/BuildConfig.*',
            ]
    )
    reports {
        xml.enabled = true
        html.enabled = true
    }
}

then I run the test task and coverageReport task:

gradle clean test
gradle coverageReport

At last, I got a Exception:

Incremental java compilation is an incubating feature.
:myLibrary:coverageReport FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':myLibrary:coverageReport'.
> org/jacoco/core/analysis/ICoverageNode

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

BUILD FAILED

My gradle version is 2.1.0, android gradle plugin version is 2.10.0, jacoco agent version is 0.7.1.201405082137
What’s wrong with my config?Anyone can help me, thx