From 00cc8ca22310a761a277fc8f3f60b887ac520f89 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sun, 22 Nov 2026 17:14:11 +0100 Subject: [PATCH] Cut clean probe build from 59 s to ~40 s Build cache, Dart compile ordered first in :app, and debug APKs without 32-bit ABIs or the Vulkan validation layer. Co-Authored-By: Claude Opus 5.5 --- DOCS-morning-session.md | 21 ++++++++++++++++++++ phone_app/android/app/build.gradle.kts | 27 ++++++++++++++++++++++++++ phone_app/android/gradle.properties | 4 ++++ 3 files changed, 52 insertions(+) diff --git a/DOCS-morning-session.md b/DOCS-morning-session.md index e4e23a3..a8cfe79 100644 --- a/DOCS-morning-session.md +++ b/DOCS-morning-session.md @@ -184,3 +184,24 @@ leg and during a ring. `flutter build apk --debug --target` produced an APK that ran `main.dart` instead; `flutter run -t` did not. The phone remains the only test of the AlarmManager deadline with the screen off and the app swiped away. + +A clean-tree `flutter build apk --debug -t lib/main_session_probe.dart` +held a build slot for 62 s (board build, load ~18). Measured back to back +on 2026-11-22 at load ~12: 54.5 s at the old HEAD, 41.5 s and 35.7 s with +these three changes (59.4 s before them at load ~18): + +- `org.gradle.caching=true` (`android/gradle.properties`): a fresh worktree + pulls plugin, Kotlin and dex outputs from `~/.gradle/caches/build-cache-1`. +- `app/build.gradle.kts` runs `compileFlutterBuild` (the ~20 s Dart + kernel compile) before `preBuild`. Gradle runs one task per + project at a time without the configuration cache, which FlutterTask does + not support; the compile used to start 8 s late and block Kotlin, dex and + manifests behind it. +- Debug APKs drop `lib/armeabi-v7a`, `lib/x86` and the engine's Vulkan + validation layer: debug installs only reach the arm64 Pixel and the + x86_64 emulator. The APK shrinks from 182 MB to 134 MB, and merging and + zipping it gets faster. Release keeps every ABI. + +What stays fixed: ~20 s of Gradle start and configuration (`~/.gradle` +sets `daemon=false`, so every build pays a cold JVM) and the Dart compile +of a 106 MB `app.dill`. diff --git a/phone_app/android/app/build.gradle.kts b/phone_app/android/app/build.gradle.kts index 2805188..1533e85 100644 --- a/phone_app/android/app/build.gradle.kts +++ b/phone_app/android/app/build.gradle.kts @@ -84,3 +84,30 @@ dependencies { // that needs a Context stays out of them. testImplementation("junit:junit:4.13.2") } + +// Start the Dart compile first. Without the configuration cache (Flutter's +// FlutterTask does not support it) Gradle runs one :app task at a time, and +// `compileFlutterBuild` sat ~190th in the plan: on a clean tree it +// started ~8 s in, after :app had idled waiting on plugin resources, then +// held :app for ~20 s while Kotlin, dex and manifests queued behind it. +// Running it before preBuild overlaps it with the plugin projects. +// mustRunAfter only orders; it pulls the compile into no task graph. +tasks.matching { it.name.matches(Regex("pre\\w+Build")) }.configureEach { + val variant = name.removePrefix("pre").removeSuffix("Build") + mustRunAfter(tasks.matching { it.name == "compileFlutterBuild$variant" }) +} + +// Debug APKs only reach the Pixel 6a (arm64-v8a) and the x86_64 emulator. +// Flutter packs three ABIs into every debug APK (182 MB), and merging, +// stripping and zipping libraries no debug install loads cost the clean +// probe build seconds it does not have: the 32-bit ABIs, and the engine's +// 15 MB Vulkan validation layer, loaded only when the manifest sets +// io.flutter.embedding.android.EnableVulkanValidation (it does not). +// Release keeps every ABI. +androidComponents { + onVariants(selector().withBuildType("debug")) { variant -> + variant.packaging.jniLibs.excludes.addAll( + listOf("lib/armeabi-v7a/**", "lib/x86/**", "**/libVkLayer_khronos_validation.so"), + ) + } +} diff --git a/phone_app/android/gradle.properties b/phone_app/android/gradle.properties index e96108c..cf412a1 100644 --- a/phone_app/android/gradle.properties +++ b/phone_app/android/gradle.properties @@ -1,4 +1,8 @@ org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError +# Build cache: a fresh worktree reuses plugin/Kotlin/dex task outputs from ~/.gradle/caches/build-cache-1. +# (~/.gradle/gradle.properties wins over this file, so its daemon=false and jvmargs still apply.) +org.gradle.caching=true +org.gradle.parallel=true android.useAndroidX=true # This newDsl flag was added by the Flutter template android.newDsl=false