9to5 coverage · Docs
Android JaCoCo coverage in GitHub Actions
Upload an Android variant’s JaCoCo XML report and inspect coverage for changed Kotlin and Java source.
Choose the module, variant and test type
Android coverage depends on the Android Gradle Plugin, build variant and whether tests run on the JVM or a device. Start with one module’s debug unit tests. Device coverage and combined multi-module reports need their own execution data and report task.
Use the report task already maintained by your project when possible. Enable XML output, then confirm its source paths line up with the repository. An HTML report or a raw .exec file cannot be uploaded as JaCoCo XML.
Configure an existing JaCoCo report task
For an existing custom jacocoTestReport task of type JacocoReport, the following Kotlin DSL configuration requests XML. This configures a task; it does not create one or infer Android class directories.
tasks.named<JacocoReport>("jacocoTestReport") {
reports {
xml.required.set(true)
xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/coverage.xml"))
}
}Import org.gradle.testing.jacoco.tasks.JacocoReport if the type is not already available. Your report task must consume the variant’s execution data, compiled Java/Kotlin classes and source directories. Keep exclusions intentional; generated classes and application source should not be confused.
Upload the variant report
# Example for a module named app with a configured jacocoTestReport task:
- run: ./gradlew :app:testDebugUnitTest :app:jacocoTestReport
- uses: 9to5/9to5-coverage-action@v1
with:
token: ${{ secrets.COVERAGE_UPLOAD_TOKEN }}
path: app/build/reports/jacoco/coverage.xmlRun these steps after checkout and your project’s JDK/Android SDK setup. Use the checked-in Gradle wrapper and replace module/task names for flavors such as demoDebug. Add the token as an Actions secret and run a matching report on the base branch.
Verify the source mapping
- Confirm the XML includes sourcefile entries and covered/missed line counters for the Java and Kotlin files changed in the PR.
- A successful unit-test task can still leave the wrong variant’s XML on disk. Confirm the selected task and fresh report path.
- For instrumented tests, collect device execution data and generate the corresponding XML before uploading; do not label JVM-only coverage as device-test coverage.