free geoip
92

Tips to Reduce Flutter App Size in Production

Reducing your Flutter app size is essential when you’re preparing for production. Large app sizes often discourage users from downloading,…

Reducing your Flutter app size is essential when you’re preparing for production. Large app sizes often discourage users from downloading, especially in regions with slower internet speeds or limited data plans. Fortunately, Flutter offers various methods and best practices to minimize the final APK or IPA size without compromising core functionalities.

Reduce Flutter App Size

Why App Size Matters

Users care about storage. A few extra megabytes can be the deciding factor for someone to uninstall or avoid installing your app. A leaner app also means faster downloads, reduced device load, and better performance.

Tips to Reduce Flutter App Size in Production

1. Use –split-per-abi

By default, Flutter builds a fat APK that includes binaries for all architectures. Instead, generate smaller APKs for each architecture:

flutter build apk --split-per-abi

This generates separate APKs for ARMv7, ARM64, and x86_64, drastically reducing the overall size of each APK.

2. Remove Unused Resources and Packages

Analyze your app and remove unused:

  • Dart packages (check pubspec.yaml)
  • Images, fonts, and other assets
  • Permissions not being used (in AndroidManifest.xml or Info.plist)

Tools like Dart DevTools can help you profile your app and detect unnecessary dependencies.

3. Enable Proguard and R8 (Android Only)

Enable code shrinking and obfuscation to remove unused classes and methods:

android {
   buildTypes {
      release {
         shrinkResources true
         minifyEnabled true
         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
   }
}

4. Use Deferred Components (Split AOT Compilation)

Flutter supports deferred components or code splitting, allowing parts of the code to load on demand instead of bundling everything at once. This is helpful especially for large apps like games or apps with multiple modules.

5. Compress Assets Before Packaging

Optimize images with tools like:

  • TinyPNG
  • ImageOptim
  • WebP format

Avoid using raw or high-resolution images if not necessary. Also, compress audio files using efficient codecs like .aac or .ogg.

6. Build in Release Mode

Never deploy debug or profile builds. Always use:

flutter build apk --release

This applies optimizations like tree shaking, AOT (ahead-of-time) compilation, and code minification.

7. Avoid Using Too Many Plugins

Each plugin adds size. If you only use a small part of a plugin, consider writing native code for that functionality instead.

8. Remove Debug Symbols (iOS)

In your iOS build settings (Xcode), strip debug symbols and unnecessary architectures.

Comparison Table: Default vs Optimized Build

ConfigurationApp Size BeforeApp Size After
Fat APK38 MB
Split-per-ABI (ARM64)11 MB
ShrinkResources Enabled38 MB9.8 MB
After All Optimizations38 MB8.3 MB

Additional Resources

For more optimization tips, see this Flutter official documentation on reducing app size.

rysasahrial

Leave a Reply

Your email address will not be published. Required fields are marked *