MyFamilyTracker
Real-time family location sharing — Firebase Realtime DB for sub-second propagation, WorkManager + ForegroundService for OS-compliant background collection, geofencing via Google Maps API.
A slow Gradle build kills developer productivity. Every wasted build minute multiplies across your team and across your day. Here's how to diagnose and fix the most common Android build performance problems.
On this page
A 5-minute build run 20 times a day costs 100 minutes. In a week, that's over 8 hours. Build performance is not a nice-to-have.
Here's how to find what's slow and fix it.
You can't optimize what you don't measure. Run a profiled build:
./gradlew assembleDebug --profile --scan--profilebuild/reports/profile/--scanLook for:
The biggest quick win for most Android projects:
// gradle.properties
org.gradle.caching=true
org.gradle.configuration-cache=trueBuild cache: Gradle stores outputs of tasks. If the inputs haven't changed (source files, config), the cached output is used instead of rerunning the task.
./gradlew assembleDebugConfiguration cache: Stores the build configuration phase. When your build scripts and settings haven't changed, Gradle skips reconfiguration entirely. Can save 10-30 seconds on large projects.
# Check if your build is cache-compatible
./gradlew help --configuration-cacheGradle defaults to a small heap. Android builds need more:
// gradle.properties
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m -XX:+UseG1GC-Xmx4gToo little heap means constant GC pressure and slower builds.
Multi-module projects can build modules in parallel:
// gradle.properties
org.gradle.parallel=trueThis requires that your modules have correct dependency declarations — Gradle needs to know which modules depend on which to parallelize safely. If modules have incorrect dependencies, you'll get flaky builds. Most well-structured projects handle this fine.
The Kotlin compiler daemon stays running between builds to avoid JVM startup overhead:
// gradle.properties — already enabled in modern projects
kotlin.daemon.jvm.options=-Xmx2gSet the daemon heap to 2GB for large projects. Too small causes GC pressure in the compiler.
KAPT (Kotlin Annotation Processing Tool) runs in a separate JVM process. KSP (Kotlin Symbol Processing) runs in the compiler directly and is 2-3x faster:
// Before: KAPT
plugins {
id("kotlin-kapt")
}
dependencies {
kapt("com.google.dagger:hilt-android-compiler:2.51")
kapt("androidx.room:room-compiler:2.6.1")
}
// After: KSP (check library docs for KSP support)
plugins {
id("com.google.devtools.ksp") version "2.1.20-1.0.29"
}
dependencies {
ksp("com.google.dagger:hilt-android-compiler:2.51")
ksp("androidx.room:room-compiler:2.6.1")
}Hilt, Room, Moshi, Retrofit all support KSP. The switch alone can save 30-60 seconds per build on annotation-heavy projects.
Incremental compilation only recompiles changed files. This is enabled by default in Kotlin/Gradle but can be inadvertently broken:
// gradle.properties
kotlin.incremental=true
kotlin.incremental.android=trueWhat breaks incremental compilation:
If you have a monolithic app module, consider splitting it:
:app (thin layer — Activity, navigation)
├── :feature:tasks (task list, detail screens)
├── :feature:settings (settings screens)
├── :core:data (repositories, database)
├── :core:network (API client)
└── :core:ui (shared components)Benefits:
:feature:settings:feature:tasks| Optimization | Effort | Impact |
|---|---|---|
| Gradle build cache | Low | High |
| KSP instead of KAPT | Low-Medium | High |
| Increase JVM heap | Low | Medium |
| Configuration cache | Low | Medium |
| Parallel builds | Low | Medium |
| Module splitting | High | High (for large projects) |
Start with the low-effort, high-impact items. Measure after each change.
Before and after optimization:
# Clean build (measures worst case)
./gradlew clean assembleDebug
# Note time
# Incremental build (change one file)
touch app/src/main/java/com/yourapp/MainActivity.kt
./gradlew assembleDebug
# Note time — should be much fasterTarget: clean build under 2 minutes for small apps, under 5 minutes for large apps. Incremental build under 30 seconds.
--scanSudarshan Chaudhari
AI Systems Builder / Product Engineer
Bangkok, Thailand
Solo Android developer with 13+ years in QA, building Android apps, AI automation systems, and developer tools at SudarshanTechLabs.
Related Posts
Related Apps
Real-time family location sharing — Firebase Realtime DB for sub-second propagation, WorkManager + ForegroundService for OS-compliant background collection, geofencing via Google Maps API.
Building something? Available for Android dev and QA consulting.
Work with meComments — powered by Giscus