Sub topic 2
Where Your App’s Bytes Come From
This chapter assumes you can run a Flutter app, edit pubspec.yaml, and use basic Dart and Flutter commands. You should also know that Flutter supports debug, profile, and release build modes.
A Flutter app’s size is the result of several parts packaged together. The Dart files you write are only one part. A release build usually contains the Flutter engine, compiled Dart code, assets, fonts, and native libraries from plugins.
The main parts of an app
| Part | What it contains | Common causes of growth |
|---|---|---|
| Flutter engine | Rendering, text, animation, and platform integration code | Engine features and target platform |
| Compiled Dart code | Your application and package code | Many packages, large features, unused code that cannot be removed |
| Assets and fonts | Images, icons, audio, JSON, and font files | Large images, duplicate files, broad font families |
| Native libraries | Android, iOS, or plugin-specific compiled code | Plugins with SDKs, multiple CPU architectures, unused native features |
The exact size depends on the platform and build format. An Android APK may contain native libraries for one or more CPU architectures. An Android App Bundle can contain several architecture-specific variants, while Google Play delivers the variant needed by a device.
The Flutter engine
The engine provides capabilities that your Dart code uses but does not implement itself. It includes the rendering pipeline, text layout, accessibility integration, asset loading, and communication with the operating system.
This baseline cost exists even for a nearly empty Flutter application. Adding a widget does not usually add a separate copy of the engine. The engine is shared by the whole application.
Debug builds can be much larger because they include development services and are not optimized for shipping. They are useful for development, but their size is not a useful release-size target.
Compiled Dart code
In a release build, Dart code is compiled ahead of time into native machine code. The compiler can apply tree shaking, which removes code that it can prove the application never uses.
Tree shaking is most effective when dependencies expose small, separable features. A package that includes a large SDK may add considerable code even when you use only one feature. Dynamic behavior, reflection-like patterns, or broad registration mechanisms can make unused code harder to remove.
Your own code can also increase size through duplicate implementations, embedded data, or features that are always included in the initial application.
Assets and fonts
Assets are files copied into the application package. Common examples include:
- Raster images such as PNG and JPEG files
- SVG icons
- Audio and video
- Local JSON or database files
- Custom fonts
A high-resolution image can occupy more space than many Dart classes. Font files can also be expensive, especially when they contain many scripts or weights. A font with regular, medium, bold, and italic variants adds each variant separately.
Compression helps package size, but it does not make an unnecessarily large source asset free. Keep only the resolutions, formats, font weights, and character ranges that the application needs.
Native libraries and plugins
A Flutter plugin may include Dart code and native code. Native code can connect to services such as maps, cameras, databases, or payment systems. Its dependencies may include precompiled libraries and resources that are not visible in your Dart files.
The same native feature may be packaged once per supported CPU architecture. Therefore, a universal artifact can be much larger than the download delivered to one device.
A useful size model
Think of the shipped artifact as:
package size = engine + compiled code + assets and fonts + native libraries + packaging overhead
This model helps you choose where to investigate. If an image change causes a large increase, inspect assets. If adding one plugin causes a jump, inspect its Dart and native dependencies. If the universal APK is large but device downloads are reasonable, CPU architectures may explain the difference.
Exercise
A new plugin increases the release APK by 18 MB, while your Dart code changed by only a few lines. Which parts should you investigate first?
Show answer
Inspect the plugin's native libraries, transitive dependencies, bundled resources, and supported CPU architectures. The Dart diff does not represent the plugin's full packaged cost.