Skip to content

chore: add Kotlin code coverage via JaCoCo#264

Open
mfazekas wants to merge 4 commits into
mainfrom
feat/android-kotlin-coverage
Open

chore: add Kotlin code coverage via JaCoCo#264
mfazekas wants to merge 4 commits into
mainfrom
feat/android-kotlin-coverage

Conversation

@mfazekas
Copy link
Copy Markdown
Collaborator

@mfazekas mfazekas commented May 19, 2026

Opt-in Kotlin code coverage for android/ files using JaCoCo offline bytecode instrumentation.
Activated by passing -PRive_KotlinCoverage=true to Gradle.

Usage

cd example/android && ./gradlew assembleDebug -PRive_KotlinCoverage=true && cd ../..
# install on emulator, run harness tests, then:
bash scripts/android-coverage.sh

How it works

  • android/build.gradle uses JaCoCo ant task to offline-instrument class files after Kotlin compilation, and saves original classes for report generation
  • jacoco-agent.properties with output=none prevents the agent from trying to auto-dump to the read-only root filesystem
  • CoverageHelper.kt flushes JaCoCo execution data on a 1s timer and activity lifecycle
  • CoverageInitProvider bootstraps CoverageHelper via a ContentProvider
  • scripts/android-coverage.sh pulls .ec files from the emulator via tar and generates reports

Results

8/8 harness test suites pass, 36.3% line coverage (538/1481 lines) across the library.
Non-coverage builds unaffected (BuildConfig flag compiles out coverage bootstrap).

mfazekas added 4 commits May 19, 2026 09:18
enableAndroidTestCoverage only instruments classes for the androidTest
variant, not the regular debug APK. Switch to offline instrumentation
via jacococli ant task that rewrites class files after Kotlin compilation.
Also fix .ec file pull to use tar for reliability across multiple
app restarts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant