My simple Flutter app is hitting 30MB for a basic CRUD tool, which seems excessive compared to native. I've already tried the --split-per-abi flag for Android, but my iOS build is still quite large. Are there specific ways to "tree-shake" unused icons or optimize the Skia/Impeller engine components to bring the download size down for users in low-bandwidth areas?
3 answers
The base size of Flutter is about 4-5MB because it bundles the C++ engine. To shrink the rest, start by auditing your assets. Use 'flutter_launcher_icons' carefully and compress all images using WebP format. In a 2023 audit, I found that removing unused Google Fonts and specifically defining only the needed weights saved us 4MB alone. Also, make sure you aren't bundling large JSON files in your 'assets' folder; instead, fetch them from a CDN. Lastly, use the 'analyze-size' flag during build to see exactly which packages are the heaviest.
Are you using many third-party packages? Every time you add a library, you're potentially pulling in native dependencies that don't always get stripped out during the compilation process.
ProGuard and R8 for Android are essential. They don't just shrink the code; they also obfuscate it, which is great for security. Make sure your 'proguard-rules.pro' is set up.
Susan is spot on. For iOS, also ensure you're doing a Release build in Xcode, as the Debug symbols can easily double the size of the generated binary during testing.
James, I actually have about 15 dependencies including Firebase and some UI kits. I noticed that 'material_design_icons_flutter' adds a lot of weight. Is there a way to only include the specific icons I'm using? I’ve seen some articles on icon tree-shaking, but I’m not sure if it’s enabled by default in the latest stable channel or if I need to add a specific flag in the pubspec.yaml.