Skip to content

Setting Up the Size Analyzer

What you'll learn

  • Generating the Size Analyzer devtool and integrating it into the monorepo toolkit
  • Building with --analyze-size and comparing against a committed baseline
  • Blocking PRs that exceed the baseline unexpectedly
  • Updating the baseline when a size increase is intentional

Prerequisites

Pro Feature

size_analyzer is available on the Pro tier and above.

Step 1: Generate the Size Analyzer

bash
archipelago generate size_analyzer

You will be prompted for:

  • appNameMyApp (must match your monorepo app name)
  • isForMonorepotrue (registers the command into the monorepo toolkit)

Or use a config file:

json
{
  "appName": "MyApp",
  "isForMonorepo": true
}
bash
archipelago generate size_analyzer --config size_analyzer_config.json

Step 2: Understand the Generated Structure

devtools/scripts/size_analyzer/
├── lib/
│   └── src/
│       ├── size_analyzer_command.dart   # Registered toolkit command
│       ├── parser.dart                  # Parses Flutter --analyze-size JSON
│       └── diff.dart                    # Diffs against baseline
└── pubspec.yaml

size_baseline/
├── android.json                         # Committed baseline (Android arm64)
└── ios.json                             # Committed baseline (iOS)

The post_gen hook registers size-analyzer into your monorepo toolkit and scaffolds the initial size_baseline/ directory with empty baseline files. Commit both.

Step 3: Build with Size Analysis

Flutter's --analyze-size flag emits a JSON report alongside the build output. Point the analyzer at it:

bash
# Android (arm64 — closest to production device)
flutter build apk \
  --analyze-size \
  --target-platform android-arm64 \
  -t lib/main.dart
bash
# iOS
flutter build ipa \
  --analyze-size \
  -t lib/main.dart

Flutter writes the size report to .flutter-devtools/ by default. The size-analyzer command reads it from there automatically.

Step 4: Run the Analyzer

Compare the latest build against your committed baseline:

bash
# Android
dart run devtools/monorepo_toolkit/bin/monorepo_toolkit.dart \
  size-analyzer analyze --platform android

# iOS
dart run devtools/monorepo_toolkit/bin/monorepo_toolkit.dart \
  size-analyzer analyze --platform ios

The command exits non-zero if the build is larger than the baseline, making it suitable for CI gating.

Step 5: Update the Baseline

When a size increase is deliberate (new feature, upgraded dependency), update the committed baseline:

bash
dart run devtools/monorepo_toolkit/bin/monorepo_toolkit.dart \
  size-analyzer update-baseline android

dart run devtools/monorepo_toolkit/bin/monorepo_toolkit.dart \
  size-analyzer update-baseline ios

Commit the updated size_baseline/*.json files alongside the code change so reviewers can see the intentional size delta in the PR diff.

Step 6: CI Integration

Add a size-check step to your PR workflow:

yaml
- name: Build with size analysis (Android)
  run: |
    flutter build apk \
      --analyze-size \
      --target-platform android-arm64 \
      -t lib/main.dart

- name: Check size against baseline
  run: |
    dart pub global activate --source path devtools/monorepo_toolkit
    monorepo_toolkit size-analyzer analyze --platform android

The step fails if the binary exceeds the committed baseline, blocking the PR until the developer either fixes the regression or explicitly updates the baseline.

Common Customizations

CustomizationWhere to Change
Change size threshold toleranceSizeAnalyzerCommand — add a --threshold flag
Track additional platformsRun update-baseline <platform> for each target
Visualise size breakdownOpen .flutter-devtools/ JSON in Dart DevTools

Next Steps

Built by Banua Coder