Reputation: 141
There is an Android app that is implemented with ionic4
and I implemented same functionality in other app written in flutter
but the ionic apk
file size is only 13MB
. With similar functionality flutter apk
(Implementation still incomplete) file size is 21MB
.
I have following questions:
I want to understand what is possibly making my apk
bigger?
Could it be related to the code implementation or something else?
Someone help me reduce the app flutter
size?
Upvotes: 5
Views: 891
Reputation: 22437
Please note these too:
If you build your apk using flutter build apk
it will contains both arm-32 and arm-64 apks(Which flutter will show in conole when you building apk). If you are building app bundle this is not an issue and its size is much smaller.
To avoid one flat apk containing arm-32 and arm-64, you can build them separately using below two commands:
flutter build apk --target-platform=android-arm
Above will produce arm-32
bit apk. Go to project -> build -> app -> release
and rename the apk to this: app-armeabi-v7a-release.apk
.
then increment version code in pubspec.yaml, next flutter pub get
and do this:
flutter build apk --target-platform=android-arm64
Above will produce arm-64
bit apk. Go to project -> build -> app -> release
and rename the apk to this: app-arm64-v8a-release.apk
.
Then you can submit two apks separately(lower apk version first).
Since, you have to run two commands by incrementing version code, flutter made it easier by this command (flutter > 1.5.4 I think): flutter build apk --split-per-abi
. That command will increment apk version code for the second apk and give you two renamed apks (Please note that this command will produce with higher version code(ex: 3222)).
From doc:
From the command line:
Enter cd <app dir> (Replace <app dir> with your application’s directory.) Run `flutter build apk --split-per-abi` (The flutter build command defaults to `--release`.)
This command results in two APK files:
<app dir>/build/app/outputs/apk/release/app-armeabi-v7a-release.apk <app dir>/build/app/outputs/apk/release/app-arm64-v8a-release.apk <app dir>/build/app/outputs/apk/release/app-x86_64-release.apk
Removing the
--split-per-abi
flag results in a fat APK that contains your code compiled for all the target ABIs. Such APKs are larger in size than their split counterparts, causing the user to download native binaries that are not applicable to their device’s architecture
Also, check these:
If you have too many fonts that will affect apk size heavily and flutter also made a solution for that by creating a package for you to get fonts from google fonts library(awesome package that give you access to so much fonts and flexibility to use anywhere). Get the package here and Read more here.
Upvotes: 1
Reputation: 1561
Did you build the Flutter apk as debug or release? That makes a big difference on apk file size. Also, Flutter and Ionic are different frameworks so is not rare to have different apk sizes (For more details about why the Ionic has an smaller file size you can check this, not only compare the sizes but performance, ease of use, etc).
Respect to your second question: What can you do to reduce the Flutter apk size?
Upvotes: 2