Slow build times are the single biggest bottleneck in daily Android development cycles. Waiting 3 minutes for a task configuration or incremental compilation kills developer momentum.
In this guide, we will implement the two highest-impact optimizations for modern multi-module Android projects: JVM compiler daemon tuning and centralizing build logic via precompiled Kotlin DSL convention plugins.
⚡ Step 1: High-Impact JVM Properties
Gradle runs tasks in background compiler processes called daemons. By default, these processes are memory-constrained. Add these switches to your root-level gradle.properties file to configure parallel execution, task caching, and garbage collector parameters:
# Enable parallel module compilation
org.gradle.parallel=true
# Cache task inputs and reuse previous outputs
org.gradle.caching=true
# Skip configuration phase by reusing task graphs
org.gradle.configuration-cache=true
# Allocate heap space and G1 Garbage Collector
org.gradle.jvmargs=-Xmx4g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+HeapDumpOnOutOfMemoryError
# Non-transitive R classes to isolate resource changes
android.nonTransitiveRClass=true
Why G1GC?
The G1 Garbage Collector (G1GC) divides the JVM heap into regions and performs incremental collections. This prevents long, freezes during compilation, preserving compiler speed for incremental builds.
🛠️ Step 2: Composite Builds & Precompiled Kotlin DSL Plugins
In multi-module configurations, copying configuration scripts across modules leads to configuration drift and slows down compilation. In 2026, standard architectures use composite builds inside a build-logic folder.
1. Include build-logic in settings.gradle.kts
// settings.gradle.kts
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
includeBuild("build-logic")
2. Define the Android Library Convention
Create a precompiled script in build-logic/convention/src/main/kotlin/android.library.gradle.kts:
// android.library.gradle.kts
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}
android {
compileSdk = 35
compileOptions {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
kotlinOptions {
jvmTarget = "21"
}
}
3. Apply the custom plugin in modules
Now, feature modules only need a single line of plugin declaration, eliminating hundreds of lines of boilerplate across the project:
// app/feature-auth/build.gradle.kts
plugins {
id("android.library") // Applies our custom convention plugin
}
📂 Download the Full 15-Page Playbook (Free PDF)
These configuration files and composite build blueprints are part of the AndroidDev Suite resources. If you want the complete, print-ready 15-page vector playbook—which includes KAPT to KSP migrations, build scan audits, and CI/CD compiler caching rules—download the PDF reference card below:
➡️ Download the Free Playbook on Gumroad
The open-source code and sample configurations are free to browse on GitHub: android-digital-products.
Top comments (0)