Gradle, Testing, and CI/CD
Scope: Gradle Wrapper/AGP/Kotlin compatibility, version catalogs, build performance (caches, incremental builds), multi-module structure, testing (unit/instrumented/Lint/Detekt/coverage), and CI quality gates including secure signing.
No universal coverage threshold, and no blind tool upgrades. Coverage targets and upgrade timing depend on the project's risk profile, team size, and release cadence — recommend a number or a version bump only with a stated reason, and check actual AGP/Gradle/Kotlin/JDK compatibility before suggesting any upgrade (see §1).
1. Gradle Wrapper, AGP, and Kotlin compatibility
- Always check the Gradle Wrapper version (
gradle/wrapper/gradle-wrapper.properties) against the Android Gradle Plugin (AGP) version in use — AGP releases document a required minimum (and often maximum-tested) Gradle version; mismatches are a common source of opaque build failures. - The Kotlin Gradle plugin version also has compatibility ranges with both Gradle and AGP — don't bump one without checking the other two, and check the project's compiled/target/min SDK and JDK toolchain version against the new AGP's requirements before recommending a bump.
- Treat "upgrade to the latest AGP/Gradle/Kotlin" as a change with its own testing burden (clean build, full test suite, release build signing check) — recommend it as a deliberate, scheduled change, not a drive-by fix bundled into an unrelated PR.
2. Version catalogs and dependency management
- Prefer a Gradle version catalog (
gradle/libs.versions.toml) over scattered version strings in each module'sbuild.gradle(.kts)— it's the current standard for centralizing dependency versions across a multi-module project. - If a project doesn't yet use a version catalog, migrating is a reasonable improvement to propose, but scope it as its own change, not bundled silently into an unrelated feature PR.
- If a project still uses
kaptfor annotation processing (Room, Hilt, Moshi codegen, etc.), migrating the processors that support it to KSP is usually a safe, high-value build-speed win — KSP avoids kapt's Java-stub generation step and is substantially faster in practice. Migrate a processor fully to KSP rather than running both kapt and KSP side by side for the same annotation long-term. - Flag duplicate/conflicting transitive dependency versions (
./gradlew :module:dependenciesor--scan) rather than guessing at version resolution; Gradle's dependency resolution result is authoritative, not a static read of the catalog file.
3. Build performance: caches and incremental builds
- Confirm configuration cache and the build cache are enabled (
gradle.properties:org.gradle.configuration-cache=true,org.gradle.caching=true) where the Gradle/AGP version supports it — these are usually the single biggest, lowest-risk build-speed wins available. - Check for configuration-cache-incompatible plugins/tasks (Gradle reports these explicitly when the cache is enabled and something breaks it) before assuming the cache "doesn't work" for a project.
- Parallel execution (
org.gradle.parallel=true) helps multi-module builds but only if modules are structured to actually parallelize (see §4) — enabling it on a single-module or heavily-linear-dependency-chain project won't help much. - Measure build-performance claims with
--profileor a build scan (--scan), the same way a performance claim elsewhere needs a profiler trace — "builds feel faster" isn't a measurement.
4. Multi-module builds and convention plugins
- Module boundaries should reflect actual build-graph parallelism opportunities and visibility boundaries (e.g. a
:feature:xmodule shouldn't be able to reach into another feature's internals) — not just a 1:1 mirror of package structure that could've stayed single-module. - Convention plugins (a
build-logic/buildSrcmodule applying shared Gradle config) are the standard way to avoid copy-pastedbuild.gradle.ktsboilerplate across many modules — recommend them once a project has enough modules that config drift between modules becomes a real risk, not preemptively for a 2-module project. apivs.implementationdependency configuration matters for build parallelism and encapsulation:implementationdependencies don't leak to a module's consumers' compile classpath, which both speeds up incremental rebuilds (fewer modules need recompiling on a change) and prevents accidental API leakage.
5. Unit tests, instrumented tests, Lint, Detekt, coverage
- Unit tests (JVM, no device/emulator) for business logic, ViewModels, mappers, use cases — fast feedback, should be the bulk of the suite. Use
kotlinx-coroutines-test'srunTest/test dispatchers for coroutine code rather than real delays or ad-hoc threading hacks. - Prefer hand-written fake implementations (a real, simplified in-memory implementation of an interface) over mocking-library mocks where practical — a fake exercises actual behavior through a real code path and tends to stay valid as the code evolves, where a mock's stubbed
when(...).thenReturn(...)expectations can silently drift from reality. Reserve mocking libraries (Mockito/MockK) for boundaries that are genuinely impractical to fake. This generalizes regardless of whether the project uses Hilt, Koin, or manual DI to supply the fake. - Instrumented tests (on-device/emulator) for anything that genuinely needs the Android framework or real UI interaction — Compose UI tests (
createComposeRule, semantics-based assertions, not hardcoded pixel coordinates orThread.sleep) or Espresso for Views. Keep this suite smaller than the unit suite; it's slower and more flaky by nature. A few specific idioms worth checking for:- Finders matching a stable test tag (
Modifier.testTag(...)+onNodeWithTag) are more resilient than matching visible text, which breaks on copy changes/localization. - Compose's semantics finders default to the merged tree (
useUnmergedTree = false); only set ittruewhen you specifically need to assert on a merged-away child node. - Testing animations requires taking manual control of the Compose test clock (
mainClock.autoAdvance = false, thenmainClock.advanceTimeBy(...)) — leaving auto-advance on makes animation assertions race-prone. waitUntilblocks on the real wall clock;advanceTimeUntil/coroutine test-dispatcher APIs advance virtual time — mixing them up is a common source of instrumented tests that are slow in CI but don't actually wait for the right thing.androidx.test:orchestratoris declared via theandroidTestUtilconfiguration, notandroidTestImplementation— a common copy-paste dependency mistake.- Reset device/app state between instrumented test runs with
pm clear <package>for a genuinely hermetic reset;am force-stoponly stops the process, it doesn't clear data.
- Finders matching a stable test tag (
- Android Lint: run it as part of the build (
./gradlew lint), reviewlint-baseline.xmlusage so it suppresses only genuinely pre-existing, accepted issues rather than silently hiding new ones. - Detekt (or ktlint) for Kotlin static analysis/style — check whichever the project already has configured and extend its existing rule set/baseline rather than introducing a second, conflicting static analysis tool.
- Coverage: report real numbers from a tool (JaCoco, Kover) with the command that produced them — never assert a coverage percentage without having run the tool. Don't propose a universal "80%" (or any other) threshold; recommend a threshold only in service of a specific, stated goal (e.g. "don't regress critical payment-flow coverage below its current measured level").
- Screenshot/visual-regression tests (rendering a composable/view to an image and diffing against a checked-in baseline) are a distinct, cheap-to-run category worth knowing about for catching visual regressions that unit tests can't — Roborazzi and Paparazzi are both established, JVM-only (no emulator needed) options for Compose/Views. If a project doesn't have any, it's a reasonable category to suggest; if it already uses one, extend it rather than introducing the other.
6. CI pipeline quality gates, secure signing, and artifact handling
- A reasonable baseline CI pipeline: build → unit tests → lint/static analysis → (optionally) instrumented tests on an emulator or device farm → artifact produced, each as its own stage/job so a failure is attributable to a specific gate rather than one opaque "build failed" status.
- Release signing keys and store passwords must never be committed to the repo or printed in CI logs — load them from the CI platform's secret storage (encrypted secrets/variables), decode them into a gitignored location at build time, and ensure the build script doesn't
echo/log them. - Cache Gradle dependencies and the build/configuration cache between CI runs (most CI platforms have a built-in action/cache step for this) — re-downloading the dependency graph on every run is a common, easily fixed source of slow CI.
- Treat
--no-verify/skipped-signing/skipped-test flags in a CI script as a red flag worth calling out, not a convenience — if they exist, understand why before assuming they're safe to leave as-is. - Artifact handling: build outputs (APK/AAB) that contain signing material or are destined for release should have restricted access in CI artifact storage, and retention policies should match how long the team actually needs to keep them, not an indefinite default.
Sources
- Gradle configuration cache and build cache — docs.gradle.org.
- Gradle version catalogs and convention plugins — docs.gradle.org.
- Gradle dependency verification — docs.gradle.org.
- Android Gradle Plugin release notes (compatibility tables) — developer.android.com.
- Kotlin Gradle plugin compatibility — kotlinlang.org.
- Android testing fundamentals and Compose testing — developer.android.com.
- AndroidX Test / Compose testing and Test Orchestrator docs — developer.android.com (for the Compose-finder, test-clock, and orchestrator-packaging facts in §5).
- Migrate from kapt to KSP — developer.android.com (for the §2 KSP recommendation).
- Scope was cross-checked against
android-feature-skill's documented quality-gate/CI structure,rinkuniks/android-claude-skill'sgradle-setup.md/testing.mdreferences, andskydoves/android-testing-skills' Compose/JVM/instrumentation skill sets, whose specific, verifiable testing idioms (test-tag finders over text, merged-vs-unmerged semantics tree, animation test-clock control, wall-clock vs. virtual-time waits, orchestrator'sandroidTestUtilconfiguration,pm clearfor hermetic resets) are reflected in §5 above in this project's own words (structure/idioms referenced, no text copied — seedocs/SOURCE_MAPPING.md). - The KSP recommendation (§2) and the general fakes-over-mocks testing principle (§5) were cross-checked against
RanaNadeemAslam/android-ai-skills'sbuild-tooling.mdandtesting.md, generalized away from their per-file, single-stack framing (structure/idioms referenced, no text copied — seedocs/SOURCE_MAPPING.md). - The §5 screenshot-testing addition was cross-checked against
arslan555/claude-android-feature-skill'sreferences/testing.md(which names Roborazzi specifically) andrinkuniks/android-claude-skill'sreferences/testing.md, generalized into a category recommendation rather than a specific tool mandate (structure/idiom referenced, no text copied — seedocs/SOURCE_MAPPING.md).