Back to Articles

Advanced

Reducing App Size in Flutter with Deferred Components

· 8 min read

Why Size Matters

A large download size makes users abandon installation, especially on slow connections or storage-constrained devices. Google Play and the App Store tend to recommend large apps less, and in some markets a download over a certain size shows the user a warning over mobile data. Reducing size starts with measuring what's actually taking up space.

Analyzing Size: --analyze-size

When you add --analyze-size to flutter build apk or flutter build appbundle, Flutter produces a size report at the end of the build and gives you an interactive visualization you can open in DevTools. This report shows exactly how much space each package, asset or native library is using.

flutter build apk --analyze-size --target-platform=android-arm64

Usually the biggest share goes to native libraries (especially code compiled for multiple CPU architectures) and font/image assets. The report tells you exactly where to focus — letting you optimize based on measurement instead of guesswork.

Architecture-Specific APKs: --split-per-abi

By default, a single APK carries native code compiled for multiple CPU architectures, such as arm64-v8a, armeabi-v7a and x86_64, in one file — meaning most users download code they'll never run. --split-per-abi produces a separate APK per architecture; when uploaded to the Play Store, each device downloads only the APK matching its own architecture.

flutter build apk --split-per-abi

If you're distributing through the Play Store, using flutter build appbundle (Android App Bundle) instead of an APK is usually better; the Play Store generates an optimized APK containing only what each device needs, and you don't need --split-per-abi manually.

Lazy Loading with Deferred Components

If your app has a large feature most users never touch (say, a rarely-opened PDF editor or an AR module), you can split that code out as a deferred component instead of bundling it in the main download. When the user opens that feature for the first time, the needed code arrives as an extra download while the app is already installed.

import 'package:pdf_duzenleyici/pdf_duzenleyici.dart' deferred as pdfDuzenleyici;

Future<void> pdfDuzenleyiciyiAc() async {
  await pdfDuzenleyici.loadLibrary();
  Navigator.push(
    context,
    MaterialPageRoute(builder: (_) => pdfDuzenleyici.PdfDuzenleyiciSayfasi()),
  );
}

A library imported with deferred as pdfDuzenleyici isn't loaded until loadLibrary() is called. On Android, to turn this into a genuinely separate downloadable module, you need to declare dynamicFeatures in android/app/build.gradle; otherwise the deferred import just splits the code into a separate chunk that's still bundled inside the same APK (on web, it really does download as a separate JS chunk).

Cleaning Up Unused Assets and Icons

flutter build commands apply --tree-shake-icons by default, which automatically strips unused Material/Cupertino icon glyph data out of the font file. On top of that, regularly reviewing the assets list in pubspec.yaml and removing images, fonts or JSON files no longer in use is the simplest, and most overlooked, way to cut size.

Things to Watch Out For

1. Don't Distribute a Single --split-per-abi APK

If you distribute only one of the APKs produced by --split-per-abi (say, just arm64-v8a) directly to users, the app won't launch at all on devices with a different architecture. These APKs are meant to be distributed through the Play Store; the Play Store automatically matches the right APK to the right device.

2. Don't Defer Every Feature

Making a frequently-used feature deferred means the user waits for an extra download every time they need it (or at least on first use). Reserve deferred components for genuinely rare, large, optional features.

Conclusion

Reducing size starts with measurement, not guesswork: find out what's taking up space first with --analyze-size. Package per device with an Android App Bundle (or --split-per-abi if needed), split out large, rarely-used features with deferred components, and regularly clean up the asset list in pubspec.yaml. Make sure default optimizations like --tree-shake-icons are already on.