Skip to content

Optimize full Android app native AI footprint before production release #253

Description

@ucguy4u

Problem

PR #225 restored green CI after the Flutter/Dart maintenance pass and re-enabled enforced APK size gates for the lean Android variants. However, the full Android app APK remains too large for production release readiness.

Latest CI size report from PR #225:

Variant Artifact Size Gate Status
mobile-streaming app-arm64-v8a-release.apk 30.82 MiB 35 MiB Passing
tv app-arm64-v8a-release.apk 27.60 MiB 35 MiB Passing
mobile-full app-arm64-v8a-release.apk 439.92 MiB report-only Too large

The full app APK is dominated by native libraries:

mobile-full / app-arm64-v8a-release.apk breakdown
native libraries: 427.10 MiB
dex: 16.69 MiB
assets: 6.51 MiB
resources: 0.88 MiB

PR #225 intentionally made the full-app size check report-only so CI can stay green while lean variants remain protected. This issue tracks the follow-up work needed before treating the full app as production-release ready.

Context

Related PR: #225

PR #225 already completed:

  • Upgraded CI to Flutter 3.41.4 / Dart 3.11.1.
  • Fixed app analyzer/codegen blockers.
  • Added CI-only Android release signing.
  • Normalized arm64 APK output for size validation.
  • Added build_runner clean before CI codegen.
  • Added pdfx stub for lean variants.
  • Excluded LiteRT native .so files from streaming/TV APK packaging based on APP_VARIANT.
  • Restored passing lean APK gates:
    • Streaming: 30.82 MiB
    • TV: 27.60 MiB

The remaining production concern is the full app native AI footprint, especially LiteRT / on-device AI artifacts.

Scope

In scope:

  • Measure exactly which native libraries account for the 427.10 MiB full-app native footprint.
  • Decide whether full-app on-device AI should be bundled, downloaded on demand, split by flavor, or delivered through Play Feature Delivery / dynamic feature modules.
  • Implement the selected production packaging strategy.
  • Restore an enforced full-app size gate or create a documented production-specific gate if 35 MiB is no longer the correct target.
  • Update CI, release docs, and any rollout notes.

Out of scope:

Suggested Investigation Plan

  1. Generate a full release APK or AAB size breakdown using Android Studio APK Analyzer, apkanalyzer, or CI artifact inspection.
  2. Identify all large .so files and their source Maven/package dependency.
  3. Compare options:
    • Keep bundled and set a realistic full-app budget.
    • Move LiteRT/model runtime behind download-on-demand.
    • Split AI into a dedicated flavor or dynamic feature module.
    • Use Play Asset Delivery / Play Feature Delivery if suitable.
  4. Validate install/startup behavior on target Android devices, especially Pixel 9 / on-device AI paths.
  5. Update CI so the selected production artifact is enforced, not only reported.

Acceptance Criteria

  • Full-app Android artifact strategy is documented in an ADR or release runbook.
  • Native library breakdown is attached to this issue or linked from a PR.
  • Production Android artifact target is explicit: APK, AAB, dynamic feature, or download-on-demand strategy.
  • CI enforces the chosen production full-app size policy.
  • Streaming and TV APK gates remain enforced and under 35 MiB.
  • Full app build passes release signing validation in CI.
  • flutter analyze --no-fatal-infos --no-fatal-warnings passes.
  • Relevant Flutter/core package tests pass.
  • Security scans remain green: Trivy/security-scan and Snyk.
  • Release notes or docs explain any packaging/install behavior change.

Validation Commands / Checks

Use these as a baseline, adapting as needed for the selected packaging strategy:

cd app
flutter pub get
dart run build_runner clean
dart run build_runner build --delete-conflicting-outputs
flutter analyze --no-fatal-infos --no-fatal-warnings
flutter test --reporter=compact
flutter build apk --release \
  --target=lib/main.dart \
  --target-platform=android-arm64 \
  --dart-define=APP_VARIANT=full \
  --dart-define=APP_PLATFORM=mobileFull \
  --tree-shake-icons \
  --split-debug-info=build/debug-info-mobile-full \
  --obfuscate

CI checks to keep green:

  • Continuous Integration / analyze
  • Continuous Integration / lint
  • Continuous Integration / test-core
  • Continuous Integration / build-android matrix
  • PR Checks / tests
  • PR Checks / code-quality
  • Security scan / Trivy
  • Snyk
  • SonarCloud
  • Plugin Size Gate

Agent / Ownership

Primary agent: agent/performance

Supporting agents:

  • agent/ci-cd for CI gates and release workflow.
  • agent/ai-llm for on-device AI packaging decisions.
  • agent/release for production artifact policy and release readiness.

Priority / Estimate

Priority: priority/P1

Estimate: 2-4 engineering days depending on whether the solution is CI budget re-baselining, dynamic delivery, or runtime download-on-demand.

Risks

  • A naive size-gate increase could mask a poor production install experience.
  • Removing bundled AI libraries could break Gemini Nano / LiteRT runtime paths if not feature-gated correctly.
  • Dynamic delivery or download-on-demand changes can affect offline behavior and first-use latency.
  • Release artifact choice may differ between GitHub APK validation and Play Store AAB distribution; document this explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/ai-llmAI/LLM Agent tasksagent/ci-cdCI/CD & Release Agent tasksagent/performanceAPK size, performance optimizationagent/releaseRelease QA Agent tasksai-coreAI Core abstraction layerepic/apk-optimizationAPK size optimization epicplatform-androidAndroid platform specificpriority/P1High - Important but not blockingsprint-4Sprint 4 - Polish and Accessibilitytype/taskImplementation task

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions