A Gradle plugin for combined code coverage reports for Android projects.
Generating code coverage reports for Android Projects is in most cases quite easy. Unfortunately by
default (using Jacoco) code coverage is generated separately per module. This means each module
takes into account it's own sources and tests (which is in terms of domain separation fine). However
it is very common to find multi-module Android projects where only one module actually has tests.
This plugin comes in handy for those projects. It generates code coverage reports using Jacoco
taking into account all the modules and tests at once, or in other words: code in module B will show
up as "covered" when tests in Module A touch it.

How to use

Currently only modules with the plugin type com.android.application or com.android.library are
taken into account when generating the coverage report, besides this any module that does not have
testCoverageEnabled true for the selected build variant (by default: debug) will be skipped:

You can add a module by enabling testCoverageEnabled:

android {
buildTypes {
debug {
testCoverageEnabled true
}
}
}

The Android-Root-Coverage-Plugin generates a special Gradle task :rootCodeCoverageReport that when
executed generates a Jacoco code coverage report. You can either run this task directly from
Android Studio using the Gradle Tool Window (see:
https://www.jetbrains.com/help/idea/jetgradle-tool-window.html) or from the terminal.

Configuration

By default the plugin generates code coverage reports using the build variant debug for every
module. However in some cases different build variants per module might be required, especially if
there is no debug build variant available. In those cases you can configure custom build variants
for specific modules:

How to test your changes/additions?
The plugin comes with an integration test. You can run this test either by executing
gradlew clean test or run the test directly from Android Studio using a proper run/test
configuration as shown in the image (by default it generates configuration that is not compatible
with a plugin module):

Author note

Many thanks to Hans van Dam for helping with testing and the initial idea.