Gradle is a powerful compilation engine, but Android builds are notoriously sluggish when Gradle is poorly configured. A mid-sized React Native app with 200+ dependencies can take 8+ minutes to compile on stock settings. With the optimizations below, we've consistently reduced that to under 90 seconds on dedicated M4 hardware.
The bottlenecks fall into four categories: JVM startup, dependency resolution, task execution, and I/O throughput. Each requires targeted tuning.
Configure gradle.properties for Maximum Throughput
Add these flags to your project's gradle.properties file to enable parallel compilation, build daemons, configuration caching, and optimized JVM memory:
# Enable gradle daemon (persistent warm JVM process)
org.gradle.daemon=true
# Compile independent modules simultaneously
org.gradle.parallel=true
# Cache task outputs for reuse across builds
org.gradle.caching=true
# Cache the configuration phase itself (saves 3-8s per build)
org.gradle.configuration-cache=true
# Optimize JVM memory for large projects
org.gradle.jvmargs=-Xmx4g -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError
# Enable file system watching (detects changes without full scan)
org.gradle.vfs.watch=true
# Use non-transitive R classes to reduce resource processing
android.nonTransitiveRClass=true
What Each Flag Does
| Property | Default | Optimized | Impact |
|---|---|---|---|
| gradle.daemon | true | true | Keeps warm JVM between builds (saves 5-15s cold start) |
| gradle.parallel | false | true | Multi-module projects build 2-4x faster |
| gradle.caching | false | true | Skips unchanged tasks entirely (40-70% time savings) |
| configuration-cache | false | true | Caches build script evaluation (3-8s savings) |
| vfs.watch | false | true | Incremental builds skip full filesystem scans |
| nonTransitiveRClass | false | true | Reduces resource processing by 30-50% in multi-module projects |
Profiling Gradle Compilation Bottlenecks
Before optimizing, measure what's slow. Run a profile trace to generate a detailed HTML report:
# Generate build profile report
./gradlew assembleRelease --profile --no-daemon
# View the report
open build/reports/profile/profile-*.html
The report breaks down timing into configuration, dependency resolution, task execution, and artifact transforms. Focus on the slowest tasks first.
Using Gradle Build Scans
For deeper analysis, enable Gradle Enterprise build scans (free for open-source projects):
# Run with build scan
./gradlew assembleRelease --scan
# The output includes a URL to the interactive build scan dashboard
Build scans provide timeline visualizations, critical path analysis, and dependency insight reports that identify which modules and tasks dominate your build time.
Implementing Cache Warming in CI/CD
Make sure your pipelines persist and restore these directories between runs:
# Cache these directories between CI runs
# ~/.gradle/caches — downloaded dependencies and transform caches
# ~/.gradle/wrapper — Gradle distribution binaries
# ~/.android/build-cache — Android-specific compilation caches
# .gradle/ (project-level) — local build cache and file hashes
# Example: restore caches before build
tar -xzf gradle-cache.tar.gz -C $HOME/.gradle/ 2>/dev/null || true
# Build the project
./gradlew assembleRelease
# Save caches after build
tar -czf gradle-cache.tar.gz -C $HOME/.gradle caches wrapper
Restoring Gradle caches reduces dependency resolution from minutes to under 3 seconds. Our M4 Apple Silicon runners come pre-warmed with common Android SDK caches, achieving sub-minute compilation for most projects.
Optimization Results
| Optimization Stage | Build Duration | Improvement |
|---|---|---|
| Stock Settings (Cold Build) | 8m 24s | Baseline |
| + Daemon + Parallel | 4m 12s | 50% faster |
| + Build Caching | 2m 08s | 75% faster |
| + Configuration Cache + VFS | 1m 34s | 81% faster |
| + M4 Bare-Metal Hardware | 0m 48s | 90% faster |
For tips on managing Android bundle sizes after compilation, read Shrinking React Native IPAs & APKs.
References & Citations
- Gradle Build Optimization Guide: Gradle User Manual
- Android Build Performance: Android Studio docs
- Configuration Cache Documentation: Gradle Configuration Cache
- Docker container optimizations: Docker on Apple Silicon