Achieving smaller app sizes with app bundles in Flutter and Fastlane
When compiling my app with flutter build apk
, I've started receiving a message telling me to use app bundles, as they would reduce my app sizes.
You are building a fat APK that includes binaries for android-arm, android-arm64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
To generate an app bundle, run:
flutter build appbundle --target-platform android-arm,android-arm64
Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per ABI, run:
flutter build apk --target-platform android-arm,android-arm64 --split-per-abi
Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Based on their explanation at https://developer.android.com/guide/app-bundle, I could save on some size. But I don't use fancy features like dynamic features.
So I changed my script to compile with flutter build appbundle --target-platform android-arm,android-arm64
, and changed my fastlane configuration as well from:
upload_to_play_store(
track: 'alpha',
apk: '../build/app/outputs/apk/release/app-release.apk'
)
to:
upload_to_play_store(
track: 'alpha',
aab: '../build/app/outputs/bundle/release/app.aab'
)
Once it went live, I pleasantly found out that download size had gone from 24 MB to 13 MB!
Speaking of app sizes, in Google Play Publish under Android Vitals, there's a tab to visualize app size over time. In my case, there's a jump on April 8, 2019. It really doubled in size. Not sure what happened. Perhaps it's related to arm vs arm64 builds.