Sub topic 3
Measuring Flutter App Size with `--analyze-size` and DevTools
Assume you can run Flutter commands, edit pubspec.yaml, and distinguish debug, profile, and release modes. This chapter focuses on measuring Android app size before deciding what to remove or replace.
Measure a release build
Debug builds contain extra checks, symbols, and development services. Their size does not represent what users download. Measure a release build, or use the release-oriented analysis produced by the Flutter tool.
From the project directory, run:
flutter build apk --analyze-size --target-platform android-arm64
flutter build appbundle --analyze-sizeThe first command analyzes an Android APK for 64-bit ARM devices. The second analyzes an Android App Bundle, which is the usual format for Google Play uploads. Each command prints a size summary and writes a file with a name similar to app-code-size-analysis_*.json.
The JSON file contains a breakdown of compiled code. Keep it with the build output or copy it to a known location so you can compare future builds.
Understand the size categories
A Flutter application is not only your Dart source code. Its size usually comes from these areas:
| Category | What it contains | Typical questions |
|---|---|---|
| Flutter engine | Rendering, text, plugins, and runtime support | Is the selected platform correct? |
| Compiled Dart code | Your application and package code | Which feature or package added bytes? |
| Assets and fonts | Images, icons, fonts, and other bundled files | Are unused or oversized files included? |
| Native libraries | Android and plugin libraries for a CPU architecture | Are multiple ABIs shipped together? |
The engine and required platform libraries form a baseline. You usually cannot remove individual engine features safely. Your application code, dependencies, assets, and native libraries offer more practical places to investigate.
The reported size can differ from the number users see in a store. APK download size, compressed bundle size, and installed size use different packaging and compression rules. Compare the same artifact type across builds.
Inspect the report in DevTools
Open the Flutter DevTools application and choose the App Size tool. Load the generated *-code-size-analysis_*.json file. DevTools presents a treemap and category breakdown.
A treemap gives each item an area related to its contribution. Start with the largest rectangles. Expand application code, packages, native libraries, assets, and fonts. Then connect a large item to a possible change:
- A large image may need resizing or a more suitable format.
- A large font may contain many unused glyphs or weights.
- A package may include a feature your app uses only once.
- Several native libraries may represent different Android CPU architectures.
- A code increase may come from a new feature, generated code, or a transitive dependency.
Use a baseline from the previous release. A single report tells you what is large. Two reports help explain what changed.
Avoid misleading comparisons
Use the same Flutter version, build configuration, target platform, and source revision when comparing reports. Record whether you measured an APK or an App Bundle. A changed dependency or platform architecture can move the numbers even when your Dart code is unchanged.
Exercise
Why should a debug APK not be used as the main measurement for production app size?
Show answer
Debug builds include development overhead, so their contents and size do not represent the release artifact users download.