Add R8 keep rules and re-enable release minification

The previous commit disabled isMinifyEnabled/isShrinkResources as a crash
workaround (AGP 9 default minification stripped WorkDatabase_Impl's no-arg
constructor). This commit adds the proper fix:

- new android/app/proguard-rules.pro: keeps the no-arg constructor on all
  RoomDatabase subclasses (the gap the Room AAR's own consumer rule misses
  — it keeps the class name but not the reflectively-called constructor),
  plus WorkManager worker/InputMerger rules re-stated from the work-runtime
  AAR in case transitive consumer-rule propagation is incomplete through the
  Flutter plugin wrapper.
- build.gradle.kts: re-enables isMinifyEnabled=true + isShrinkResources=true
  with proguard-android-optimize.txt + proguard-rules.pro.

Verified on the real phone (BL9000): minified release APK launches without
crash, MainActivity foreground, food-bank suggestions and slot chips render
correctly. APK size 52.1 MB (vs 56.9 MB unminified).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SWPUBzE24Ls9i9GMRwXnnn
This commit is contained in:
Krzysztof kuhy Rudnicki 2026-06-25 17:34:15 +02:00
parent adbfb20e9a
commit 7d421c1d8b
2 changed files with 26 additions and 8 deletions

View File

@ -33,14 +33,12 @@ android {
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works. // Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug") signingConfig = signingConfigs.getByName("debug")
// AGP 9 defaults release minification (and resource shrinking, isMinifyEnabled = true
// which requires it) to true. R8 then strips isShrinkResources = true
// WorkDatabase_Impl's reflection-only no-arg constructor (no proguardFiles(
// keep rule covers it), crashing every release launch with getDefaultProguardFile("proguard-android-optimize.txt"),
// NoSuchMethodException. Disable both until proper "proguard-rules.pro",
// Room/WorkManager keep rules are added. )
isMinifyEnabled = false
isShrinkResources = false
} }
} }
} }

20
app/android/app/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,20 @@
# Room: keep generated *_Impl classes and their no-arg constructors.
# The Room AAR ships "-keep class * extends RoomDatabase" but that only
# protects the class from removal/renaming R8 still strips the no-arg
# constructor because it's only ever called via Class.getDeclaredConstructors()
# (reflection inside RoomDatabase.create()), which R8 cannot trace statically.
-keep class * extends androidx.room.RoomDatabase { <init>(); }
-dontwarn androidx.room.paging.**
-dontwarn androidx.lifecycle.LiveData
# WorkManager: keep worker classes, their two-arg constructors, and the
# WorkerParameters type passed to them. Sourced from work-runtime AAR's
# own proguard.txt re-stated here so they apply even if transitive
# consumer-rule propagation through the Flutter plugin wrapper is incomplete.
-keepnames class * extends androidx.work.ListenableWorker
-keepclassmembers public class * extends androidx.work.ListenableWorker {
public <init>(...);
}
-keep class androidx.work.WorkerParameters
-keepnames class * extends androidx.work.InputMerger
-keepclassmembers class * extends androidx.work.InputMerger { void <init>(); }