SwiggyPratik SahuProblem & solution
Scaling Android CI: From 44 → 10 minutes — A Deep Dive into Build Time Optimization and Best…
Summary
An Android monorepo’s CI pipeline averaged about 35 minutes in its build phase, with a P90 of roughly 44 minutes, as repeated dependency downloads, environment-driven invalidations, variant bloat, and machine limits increased work. The team reworked caching with branch- and architecture-aware keys, release/develop fallbacks, cached SDK and dependency data, and a Gradle Remote Cache, while filtering repositories and restricting CI to required variants. It also tuned 32GB runners to a 16GB heap and 12GB Metaspace, disabled configuration-cache saves in ephemeral CI, upgraded Kotlin, AGP 8.10.1, and Gradle 8.11.1, and moved critical workflows to Apple Silicon. Gradle tasks fell from 3399 to 2745, while remote-cache hit rates reached P50 44% and P90 56%. After the Apple Silicon refresh, total CI time reached P50 10 and P90 11 minutes, average credits per build dropped from 55 to 43, and a comparable rollout window saved about 5800 credits.
Context
The Android monorepo’s CI pipeline became slow and expensive as it scaled. Archive caches became less reusable when many modules changed, system properties and environment inputs triggered unnecessary reconfiguration, Gradle probed multiple repositories, CI compiled unnecessary variants, and machine constraints caused OOMs and performance variability. Under per-minute billing, each CI minute cost 2 credits.
Approach / What changed
The work combined branch- and OS/architecture-aware caching, release and develop fallbacks, selective cache saves, a Gradle Remote Cache, repository content filtering, required-variant enforcement, reduced inter-module coupling, JVM heap and Metaspace tuning, configuration-cache changes for ephemeral CI, toolchain upgrades, larger runners, and migration of critical workflows to Apple Silicon.
Takeaways
Branch-level cache saves were avoided on every run under the 2-credits-per-minute plan because saving could take 1–1.5 minutes and sometimes about 3 minutes; authoritative develop and release caches were refreshed through back-merges instead.
A Gradle Remote Cache running on a small EC2 instance with 8GB RAM and a 256GB SSD produced incremental-build hit rates of P50 44% and P90 56% in the reported results.
Restricting CI to required release variants reduced the Gradle task graph from 3399 to 2745 tasks, while configuration-cache saving was disabled after scans showed about 30 seconds spent saving data that ephemeral CI did not reuse.
Source and freshness
- Source
- medium.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.