App Size Optimization - Flutter
This guide is designed to help developers optimize app size, enhancing performance and efficiency across different devices. By following these best practices, you can reduce load times and minimize storage requirements.
Deliver Leaner Apps with App Bundles
Using Android App Bundles (AAB) is an effective way to optimize the size of your application, making it lighter and more efficient for users to download and install. App Bundles allow Google Play to dynamically generate APKs tailored to each device, so users only download the resources and code relevant to their specific configuration. This approach reduces app size significantly, leading to faster installs and conserving storage space on users’ devices.
Recommended Practices:
-
Enable App Bundles: Configure your build to use the App Bundle format instead of APKs. This will allow Google Play to optimize your app for each device type automatically. -
Organize Resources by Device Type: Ensure that resources (like images and layouts) are organized by device type (such as screen density or language) to maximize the benefits of App Bundles. -
Build for ARM ABIs Only: The SDK ships its native libraries forarm64-v8aandarmeabi-v7aonly. Building your app for those ABIs alone leaves out native libraries for devices the SDK cannot run on, and keeps Google Play from offering your app to those devices. See Supported ABIs for the build settings. -
Test Modularization: If your app contains large, optional features, use dynamic feature modules to let users download them on demand. This reduces the initial download size and provides features only as needed. -
Monitor Size Reductions: Regularly analyze your app size to see where the most savings occur, and make sure that App Bundle optimizations are effectively reducing your app size across different device configurations.
Optimize Libraries for a Leaner App Experience
Managing dependencies carefully is essential for minimizing app size and improving performance. Every library or dependency included in your app adds to its overall size, so it’s crucial to only incorporate what’s necessary. Optimizing dependencies helps streamline your app, reduce load times, and enhance maintainability.
Recommended Practices:
-
Use Only Essential Libraries: Review all libraries and dependencies, removing any that are not critical to your app’s functionality. This helps avoid unnecessary bloat. -
Leverage Lightweight Alternatives: Whenever possible, choose lightweight libraries or modularized versions of larger ones. For example, opt for a specific feature module rather than including an entire library. -
Monitor Library Updates: Regularly update your dependencies to take advantage of any optimizations or size reductions made by the library maintainers. Newer versions are often more efficient. -
Minimize Native Libraries: If your app uses native libraries, ensure they’re essential and compatible across platforms, as they can significantly increase app size. -
Add ML Kit Only for the Effects You Use: The SDK does not bundle ML Kit. On Android, auto-framing on the defaultVideoEffectsPipeline.LEGACYneedscom.google.mlkit:face-detection:16.1.7, and background blur needscom.google.mlkit:segmentation-selfie:16.0.0-beta6. Add each one to your app'sbuild.gradleonly if you use that effect. See Video Effects. -
Analyze Dependency Tree: Use tools like Gradle’s dependency analyzer to identify unnecessary or redundant dependencies, ensuring your app’s dependency tree is as lean as possible.
Optimize with ProGuard
ProGuard shrinks, optimizes and obfuscates your code, which can significantly reduce your app's size and improve performance. By removing unused code and reducing the size of classes, fields, and methods, ProGuard helps to minimize the footprint of your app without sacrificing functionality. Additionally, ProGuard’s obfuscation feature enhances security by making reverse engineering more difficult. You can refer to the official documentation for more information.
Recommended Practices:
Enable ProGuard: Flutter already shrinks release builds with R8, which applies ProGuard rules, and reads your rules fromandroid/app/proguard-rules.pro. If your project turned this off, ensure that yourproguard-rules.profile is properly configured, and add the following lines to yourbuild.gradlefile:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Add Keep Rules for VideoSDK: R8 removes or renames classes the SDK needs at runtime unless you keep them. Add these rules to yourandroid/app/proguard-rules.profile:
-keep class videosdk.org.** { *; }
-dontwarn videosdk.org.**
Keep the -dontwarn line, because the keep rule alone fails the R8 step with a missing-class error.
Customize ProGuard Rules: Carefully review and customize ProGuard rules in the proguard-rules.pro file to avoid stripping essential code. For example, to keep a specific class, add:
-keep class com.example.myapp.MyClass { *; }
Got a Question? Ask us on discord

