Skip to content

perf(android): APK size reduction phase 1#2

Merged
priyavratuniyal merged 1 commit intomainfrom
feature/apk-size-reduction
Mar 26, 2026
Merged

perf(android): APK size reduction phase 1#2
priyavratuniyal merged 1 commit intomainfrom
feature/apk-size-reduction

Conversation

@priyavratuniyal
Copy link
Copy Markdown
Owner

@priyavratuniyal priyavratuniyal commented Mar 26, 2026

Summary

  • Split release APK per ABI (arm64 + x64 only), eliminating the 287 MB universal fat build
  • Enable R8 minification and resource shrinking for release builds
  • Exclude Vulkan debug validation layer (15 MB) from release packaging
  • Exclude unused MediaPipe image generation libs (24 MB) from release packaging

Results

APK Before After
Universal (all ABIs) 287 MB
arm64-v8a 150.1 MB
x86_64 93.3 MB

Further reduction to ~35–45 MB requires replacing flutter_gemma with llama_cpp_dart (phase 2).

Test plan

  • Release build on a real arm64 device
  • PDF import and parsing works
  • Chat / LLM inference works
  • Biomarker dashboard renders correctly

Summary by CodeRabbit

Release Notes

Chores

  • Optimized release builds to produce architecture-specific APKs for improved compatibility and reduced download sizes.
  • Enabled code minification and resource shrinking to minimize overall app size.
  • Streamlined native library packaging for more efficient builds.

…ions

- Split release APK per ABI (arm64 + x64 only), dropping universal fat build
- Enable R8 minification and resource shrinking for release builds
- Exclude Vulkan debug validation layer from release packaging
- Exclude unused MediaPipe image generation libs from release packaging
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 26, 2026

📝 Walkthrough

Walkthrough

The release build process has been updated to generate ABI-specific APKs for ARM64 and x64 architectures rather than a single universal APK. Additionally, code minification and resource shrinking have been enabled in the Android release build configuration, with specific native libraries excluded from packaging.

Changes

Cohort / File(s) Summary
Release Workflow
.github/workflows/release.yml
Modified flutter build apk command to generate ABI-split APKs using --split-per-abi flag; updated artifact renaming and GitHub Release upload to handle multiple ABI-specific APK files via glob patterns.
Android Build Configuration
android/app/build.gradle.kts
Enabled code minification (isMinifyEnabled = true) and resource shrinking (isShrinkResources = true) for release builds; added packaging block to exclude specific native shared libraries (libVkLayer_khronos_validation.so, libmediapipe_tasks_vision_image_generator_jni.so, libimagegenerator_gpu.so) from bundling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 The APKs split with purpose and care,
Each platform gets its own perfect pair,
Code shrinks down, libraries fade away,
Release builds are swifter today! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf(android): APK size reduction phase 1' accurately describes the main change—reducing Android APK size through ABI splitting, minification, resource shrinking, and exclusion of debug/unused libraries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/apk-size-reduction

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.github/workflows/release.yml (1)

40-45: Consider adding error handling for the APK rename loop.

If the build fails silently or produces unexpected output, the glob app-*-release.apk won't match any files, and bash will iterate with the literal string, causing a confusing mv error.

🛠️ Suggested improvement with error handling
       - name: Rename APKs with version
         run: |
           cd build/app/outputs/flutter-apk
+          shopt -s nullglob
+          apks=(app-*-release.apk)
+          if [ ${`#apks`[@]} -eq 0 ]; then
+            echo "Error: No APKs found matching app-*-release.apk"
+            exit 1
+          fi
           for apk in app-*-release.apk; do
             mv "$apk" "koshika-${{ github.ref_name }}-${apk#app-}"
           done
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/release.yml around lines 40 - 45, The rename loop can run
with the literal glob when no APKs exist; modify the step so you first expand
the pattern into an array (files=(app-*-release.apk)) or enable nullglob (shopt
-s nullglob) and then check if the array is empty before the for loop; if empty,
emit an error message and exit non-zero, otherwise iterate over the array (for
apk in "${files[@]}") and run mv "koshika-${{ github.ref_name }}-${apk#app-}"
only for real files to avoid spurious mv errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/release.yml:
- Around line 40-45: The rename loop can run with the literal glob when no APKs
exist; modify the step so you first expand the pattern into an array
(files=(app-*-release.apk)) or enable nullglob (shopt -s nullglob) and then
check if the array is empty before the for loop; if empty, emit an error message
and exit non-zero, otherwise iterate over the array (for apk in "${files[@]}")
and run mv "koshika-${{ github.ref_name }}-${apk#app-}" only for real files to
avoid spurious mv errors.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a1696475-d27d-4f8b-8039-55bdb048f148

📥 Commits

Reviewing files that changed from the base of the PR and between 6f533bc and 6b35f5a.

📒 Files selected for processing (2)
  • .github/workflows/release.yml
  • android/app/build.gradle.kts

@priyavratuniyal priyavratuniyal merged commit 74029b4 into main Mar 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant