Why flutter apk file size is little bigger

524

Solution 1

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?

  1. Remove packages, libs or plugins not used
  2. Check the size of assets included on app (images, videos, etc)
  3. Check if you are compiling to release or debug mode. Again, that makes the difference.
  4. If you are going to upload your apk to Google Play Store, you can build a Bundle instead of Apk. That can optimize the size of your app.

Solution 2

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

read more here.

Also, check these:

  • As other answer mentioned remove all unnecessary assets(images, fonts and files).

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.

  • Remove unnecessary packages/ plugin that doesnt use(Not much affect though).
Share:
524
user8913050
Author by

user8913050

Updated on December 16, 2022

Comments

  • user8913050
    user8913050 over 1 year

    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?