Reputation: 729
I have built an app with Flutter that is now available for both the iOS and Android platforms. I am noticing, however, that the app store download sizes seem very large. For example, for iOS, my app's ipa size is 102MB and the download size is 85MB. This is in comparison to when I create the Android appbundle, which usually comes in at around 30MB. Can someone explain to me why there is such a big difference between the iOS and Android apps? Is it just the way Flutter builds iOS apps? What can I do to remedy this?
I have also been thinking about other ways I could reduce the download size of my app. So far, I have optimised all image files for size and removed unnecessary dart files. One thing that has occurred to me is could my use of external libraries be part of the problem? For example, I use the Flutter Platform Widgets package to help provide native feel. When I use it, I import the whole file, like so:
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
Of course, that provides access to 20 - 30 or so different platform widgets each time I import it in any given dart file. Would importing the files for only the widgets that I use make a difference to the file size? For example, on a page where all I use is the platform text button, would importing only
import 'package:flutter_platform_widgets/src/platform_text_button.dart';
reduce help to reduce the file size of the app, by only importing necessary widgets, or would it not make a difference at all?
The other thing I have come across is obfuscating the code. For example, when I build the iOS version, I would run:
flutter build ios --obfuscate --split-debug-info=debug-info
I have come across answers on this forum and others where people have said they've used it and it has broken their app, giving a bad experience to the end user. Would obfuscation likely break the app for the end user and if so, what could I do to correct this? Would it actually reduce the app's download size?
Thanks for all your help! I am open to any other suggestions to reduce my app's download size as well.
Upvotes: 1
Views: 390
Reputation: 1638
Your idea of only importing the files you actually use is probably unnecessary, as the Dart compiler automatically tree-shakes, removing unused code.
In terms of obfuscation, I always use it and it has never caused any problems for me.
This is the command(s) I use:
flutter clean
flutter build apk --split-per-abi --obfuscate --split-debug-info=/symbols
In comparison to just a clean and normal build, my command has shrunk the output from 44.3MB to 12.9MB. Now, that is partially because there are now 3 apks, but most of the time only 'app-armeabi-v7a-release.apk' is needed.
I've never built for iOS before, so I can't comment much about that.
There are guides online that supposedly shrink the package more, but when I tried some of them, I spent several hours for 0.2MB gain. It's not worth it in my opinion.
Upvotes: 1