build: R8-shrink the published APK (~72 MB) — the reflection-safe way - #332
Merged
Conversation
SMK1705
commented
Jul 29, 2026
Owner
…ease-gated Enables R8 minify + resource shrinking on the published (debug-signed) build, gated behind -Pshrink so ordinary local/CI builds stay fast and un-minified. Clean-built, the primary APK drops 94 -> ~72 MB; with the arm64 slim it's now 199 -> ~72 MB (64% smaller). Details / hard-won specifics: - proguard-rules.pro: -dontobfuscate (renaming is what silently breaks reflection; skipping it keeps the risk low while still stripping dead code + resources). Keep the ML/crypto JNI libs whole (native code resolves them by name), keep app models, keep annotation/signature attributes. Hilt/Room/Retrofit/Compose consumer rules are auto-applied from their AARs. - AskConversationStore: StoredConversation/StoredTurn now carry @JsonClass(generateAdapter=true). They were the ONLY Moshi models still using the reflective KotlinJsonAdapterFactory, which needs kotlin-reflect at runtime — and R8 strips it, so persistence crashed the Ask/Settings screens under R8 (device-caught). Codegen adapters have no runtime-reflection dependency. - build.gradle.kts: debug build type sets isMinifyEnabled/isShrinkResources only when -Pshrink. - release-apk.yml: build the slim+shrunk PRIMARY first on the fresh CI tree (a -Pshrink build after a non-shrink one leaves ~20 MB of stale native-lib padding that eats the dex saving), then the universal fallback. Publishes the shrunk build at the stable taskmind-debug.apk URL. Device-verified end to end on the Galaxy S25 at 71.5 MB — the reflection gauntlet all passes: launch (SQLCipher/Room/Hilt/Compose), cloud extraction (Moshi codegen), Ask + engine, Ask thread persist AND restore across a force-stop (the StoredConversation round-trip that crashed before the @JsonClass fix), Settings, and the MediaPipe neural embedder. Note: R8 is release-only, so its build failures surface in the release workflow (runs on merge) and its RUNTIME reflection breakage only on-device — CI builds the un-minified universal. Any NEW Moshi-serialized model must use @JsonClass(generateAdapter=true), not reflection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.