Reducing Flutter App Size

App size for applications is very important. There are two dimensions to it: the download size — the size of the app on play store/when downloading/when installing and the install size — this is what happens when you download the app, unpack it, compile and optimize it. This expands the application significantly and can be two, three times or even more the install size. Why should you care about these sizes?

Download Size

When a user goes to install an app say on play store, he sees the loading bar and then the actual app size. The larger the app, the greater the chances of a failed/cancelled download. As developers, we want to get the app size small so that we get as much distribution for our app as possible.

Install Size

This has a similar phenomenon. Users fill their phones with videos, audios, images and at some point in time, they will try to install a new app and oops no space for it 😪😪😪. They will go hunting for space, go to settings, check which app consumes more space. Even while trying to download from play store, it suggests they remove some apps to accommodate the new one and even give them suggestions.

Let’s Analyze Some APK

So I will be analyzing a signed apk for a release app. I will be using the ncovid app — a COVID-19 news app with statistics and a tracker dashboard whose GitHub repo is available here. You can check the release tags on the repo. We would be analyzing the pre-release version 0.8 available here.

Let’s fire up the android studio and open the project. With the project opened on android studio, click on Build >> Analyze Apk and choose the apk of choice. The apk which I would be analyzing is available here. You should have a similar screen to what is shown below.

Analyze Apk

We can see that 95% of the app size is taken up by lib. Expanding lib, we see three different compiled binaries. What does this tell us? 🤔🤔🤔……. The command used to build the release app would have been flutter build apk --release . The analysis also tells us that the app is a fat apk that includes binaries for android-arm, android-arm64, android-x64.

Analyze Apk

Resolving fat apk issues

To resolve this, we could build an app bundle if we are uploading to playstore or we could split the apk per abi which splits the apk to x64 and x86 bit code.

To build the app bundle, we run the command flutter build appbundle which contains your dart code for the flutter runtime compiled for armeabi-v7a (ARM 32-bit), arm64-v8a (ARM 64-bit), and x86–64 (x86 64-bit) or we could split the app bundle also with the command flutter build appbundle --target-platform android-arm,android-arm64,android-x64 .