Setting Up the Size Analyzer
What you'll learn
- Generating the Size Analyzer devtool and integrating it into the monorepo toolkit
- Building with
--analyze-sizeand comparing against a committed baseline - Blocking PRs that exceed the baseline unexpectedly
- Updating the baseline when a size increase is intentional
Prerequisites
- An existing Archipelago monorepo (see Monorepo Scaffolding)
- Monorepo Toolkit already generated (see Monorepo Toolkit Setup)
Pro Feature
size_analyzer is available on the Pro tier and above.
Step 1: Generate the Size Analyzer
archipelago generate size_analyzerYou will be prompted for:
- appName —
MyApp(must match your monorepo app name) - isForMonorepo —
true(registers the command into the monorepo toolkit)
Or use a config file:
{
"appName": "MyApp",
"isForMonorepo": true
}archipelago generate size_analyzer --config size_analyzer_config.jsonStep 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:
# Android (arm64 — closest to production device)
flutter build apk \
--analyze-size \
--target-platform android-arm64 \
-t lib/main.dart# iOS
flutter build ipa \
--analyze-size \
-t lib/main.dartFlutter 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:
# 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 iosThe 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:
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 iosCommit 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:
- 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 androidThe 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
| Customization | Where to Change |
|---|---|
| Change size threshold tolerance | SizeAnalyzerCommand — add a --threshold flag |
| Track additional platforms | Run update-baseline <platform> for each target |
| Visualise size breakdown | Open .flutter-devtools/ JSON in Dart DevTools |
Next Steps
- Add the Detect New Library tool to catch unapproved dependencies before they land
- Configure Monitoring to correlate binary size with crash rates in production