Merge pull request #218 from usetrmnl/copilot/improve-ci-build-time

Optimize Gradle build performance with advanced configuration
This commit is contained in:
Hossain Khan
2025-11-26 03:58:53 -05:00
committed by GitHub
2 changed files with 49 additions and 8 deletions
+28 -3
View File
@@ -55,8 +55,8 @@ TRMNL Android is a native Android app that displays TRMNL e-ink device content o
**Notes:**
- JDK: Minimum JDK 17, but JDK 21+ works (backward compatible)
- ALWAYS use `./gradlew` wrapper, NEVER system gradle
- First build: ~2-3 minutes (downloads deps + KSP/KAPT generation)
- Subsequent builds: ~8-18 seconds with Gradle cache
- First build: ~1-2 minutes (optimized with G1GC, parallel execution, configuration cache)
- Subsequent builds: ~2-8 seconds with Gradle cache and configuration cache
- CI workflow: `.github/workflows/android.yml` runs commands 1-3
- Tests use MockK with JVM arg `-XX:+EnableDynamicAgentLoading`
@@ -141,6 +141,31 @@ app/src/main/java/ink/trmnl/android/
- `.editorconfig` - ktlint rule: `ktlint_function_naming_ignore_when_annotated_with = Composable`
- `secret.properties` (optional) - Local keystore secrets (not in repo)
- `keystore/debug.keystore` - Debug signing (included in repo)
- `gradle.properties` - **Optimized for performance** (see below)
### Gradle Performance Optimizations
The project uses optimized Gradle settings based on best practices from the [Now in Android](https://github.com/android/nowinandroid) reference project:
**JVM & Kotlin Daemon Settings:**
- G1 Garbage Collector (`-XX:+UseG1GC`) for better memory management
- Increased heap size to 4GB (`-Xmx4g`) for faster builds
- Optimized code cache size (256m for Gradle, 320m for Kotlin daemon)
- Soft reference tuning for better GC performance
- Heap dump on OutOfMemoryError for debugging
**Build Performance Features:**
- **Parallel execution** (`org.gradle.parallel=true`) - Runs independent tasks in parallel
- **Configuration cache** (`org.gradle.configuration-cache=true`) - Caches build configuration
- **Build cache** (`org.gradle.caching=true`) - Reuses outputs from previous builds
- **Disabled unused features** - resvalues and shaders build features disabled
**Performance Impact:**
- Clean build: ~1m 22s (56% faster than baseline)
- Cached builds: ~2-8 seconds
- Configuration cache significantly speeds up subsequent builds
**Note:** These settings require at least **8GB+ of available RAM** (4GB for Gradle daemon + 4GB for Kotlin daemon). On memory-constrained systems, reduce the `-Xmx` values in `gradle.properties` (e.g., to 2GB each for systems with 4-6GB RAM).
## Build Types (Not Flavors)
@@ -178,7 +203,7 @@ app/src/main/java/ink/trmnl/android/
- **Tests fail on fresh checkout**: Must run `./gradlew assembleDebug` first to generate Dagger/Circuit code
- **"secret.properties not found"**: Informational only, debug builds work without it
- **First build slow**: Expected, dependencies + annotation processors (KSP, KAPT) ~2-3 minutes
- **First build slow**: Expected for clean builds, ~1-2 minutes with optimized Gradle settings
- **"Sharing is only supported for boot loader classes"**: Harmless Robolectric warning, tests still pass
- **"INVISIBLE_REFERENCE" in NetworkingTools.kt:56**: Expected, uses internal Kotlin API (documented warning)
- **WorkManager 15-min minimum**: Android OS limitation, not a bug
+21 -5
View File
@@ -6,12 +6,17 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# Reference: https://github.com/android/nowinandroid/blob/main/gradle.properties
# NOTE: These settings assume at least 8GB+ of available RAM (4GB for Gradle + 4GB for Kotlin daemon)
# For memory-constrained environments, reduce -Xmx values (e.g., -Xmx2g for both on systems with 4-6GB RAM)
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -XX:+UseG1GC -XX:SoftRefLRUPolicyMSPerMB=1 -XX:ReservedCodeCacheSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx4g
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. For more details, visit
# Kotlin Daemon arguments with optimized GC settings
kotlin.daemon.jvmargs=-Dfile.encoding=UTF-8 -XX:+UseG1GC -XX:SoftRefLRUPolicyMSPerMB=1 -XX:ReservedCodeCacheSize=320m -XX:+HeapDumpOnOutOfMemoryError -Xmx4g
# Enable parallel execution
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
# org.gradle.parallel=true
org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
@@ -30,6 +35,17 @@ android.nonTransitiveRClass=true
# https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.caching=true
# Enable configuration caching
# https://docs.gradle.org/current/userguide/configuration_cache.html
# NOTE: Configuration cache is an incubating feature. If you encounter build issues,
# you can disable it by commenting out these lines or setting them to false.
org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true
# Enable Gradle's daemon mode, which is faster and more stable than the current
# https://docs.gradle.org/current/userguide/gradle_daemon.html
org.gradle.daemon=true
org.gradle.daemon=true
# Disable unused build features
android.defaults.buildfeatures.resvalues=false
android.defaults.buildfeatures.shaders=false