问题
Version 2.3.3 of the Android Gradle Plugin was able to provide merged unit test and connected test code coverage data. In version 3.0.0, this capability is broken because each of the test types use a different and incompatible version of JaCoCo. Rafael Toledo provided a Medium blog post showing how to make this work with 2.3.3. I have provided a Github repo that illustrates the working code and the broken code in a few branches. The repo documentation provides a Readers Digest description of the problem. At this point I am convinced the Gradle Plugin team owns the issue and will file a bug shortly. My questions are:
1) Can anyone suggest a viable workaround? (there is a suggested fix by Carmen Alvarez posted to the Medium blog post but I get no joy from it.)
2) Can someone point me to instructions on how to hack and build the Gradle Android Plugin to test out a potential fix? (I found the answer to this one at http://tools.android.com/build/gradleplugin )
回答1:
According to Android Plugin DSL Reference that contributes Android specific things:
To specify the version of JaCoCo you want to use, you now need to include it as a buildscript dependency in your project-level build.gradle file, as follows:
buildscript { dependencies { classpath "org.jacoco:org.jacoco.core:<jacoco-version>" ... } }
Previously Android Plugin had
android {
jacoco {
version = "<jacoco-version>"
}
}
According to Gradle JaCoCo Plugin documentation that contributes task of type JacocoReport
:
The JaCoCo plugin adds a project extension named jacoco of type JacocoPluginExtension, which allows configuring defaults for JaCoCo usage in your build.
jacoco { toolVersion = "<jacoco-version>" }
And so here is modification for your https://github.com/pajato/acc that allows to align versions so that execution of ./gradlew clean jacocoTestReport
succeeds:
buildscript {
dependencies {
classpath "org.jacoco:org.jacoco.core:0.7.9"
}
}
allprojects {
apply plugin: "jacoco"
jacoco {
toolVersion = "0.7.9"
}
}
来源:https://stackoverflow.com/questions/46998425/merging-android-unit-test-and-connected-test-code-coverage-data-is-broken