Reducing App Size in Flutter Mobile App Development.

ariba.dev
7 min readSep 22, 2022

--

This article is about the methods and techniques we can follow to reduce application size. If you are a mobile application developer, you are definitely concerned about app size.

Many users avoid downloading any application which is too large. According to a report, about 337 million smartphone users have limited data plans and they don’t want to waste their data on a single application. So after all the coding, it’s best to optimize and try to reduce the app size. Let’s take a look at some of the ways of reducing the Flutter app size.

Image Asset — In Flutter, developers use images from the assets folder. In development mode, dis will be useful as the images are loaded faster. But when you bundle the app these images add more weight to the app. The solution is to use network images. Upload the images in a permanent storage path like AWS and use the link to that image in you’re code.

Use Google Fonts — Similar to images, custom fonts will also increase app size. The best solution is to use the google_fonts plugin. this plugin will dynamically download a font when it is used and will download in a specific style and language.

Icons — It is recommended to use the Material Icons or Cupertino Icons class. Developers can also add –tree-shake-icons option to the flutter build command, to remove all unwanted icons from the bundle. This will potentially save the size of the app.

Cache — Using the cache will not technically help in reducing app size but it will make the app load faster and hence improve the app performance. The cached_network_image package allows you to use any widget as a placeholder.

Use Specific Libraries — Calling packages not used in pubspec.yaml file should be avoided. Once done building your app, you should check your pubspec.yaml and remove libraries that are not used. Also, remove all the unused assets from pubspec.yaml.

YOU always trying to build small-size applications and use size reduction techniques. There are two dimensions to measure app size:

  • The download size-The size of the app on the play store (when downloading)
  • Install size- This can see after installing the app. This is what happens when you download the app, unpack it, compile and optimize it.

Download Size :

When a user goes to install an app from on play store, he sees the loading bar and then the actual app size. according to google, there are 2.59 million apps on the play store and no wonder convincing a user to install your app has never been more difficult. The larger the app, the greater the chances of a failed/canceled download.

Install Size :

This has a similar phenomenon. Users fill their phones with videos, audio, and images, they will try to install a new app and oops no space for it. They will go hunting for space, go to settings, and check which app consumes more space.

there are some common methods and practices that you can implement in your app to make it better.

App size in flutter

1. Use Android App Bundle to Reduce App Size

When you has developed your android app and are ready to release your app, you has to choose between APK and Android App Bundle. The Android App Bundle will make Google play to create the APK wif only those specific users that require features.

Android App Bundle

  • For a publishing format consisting of compiled code and resources of your app, Android App Bundle is used and delays APK generation and signing to Google Play.
  • Wif Android App Bundles, the compressed download size restriction is 150 MB. The app bundle cannot be used wif APK expansion files.

2. Use Proguard

To reduce you’re app APK size, Proguard is likely one of the most useful tools. It will directly reduce the source code files to a minimum and can lower the APK file size up to 90%.

  • Whenever using “Proguard, try to use all variants.”
  • Proguard helps avoid disputes at the generated APK or bundle if used in all the variants while developing.
  • ProGuard renaming or removing any fields on these data classes is not what we can do as they have to match the serialized format.

3. Use Android Size Analyzer Plugin

To considerably reduce the size of you’re Android App, the Android Studio plugin is you option. With the APK Analyzer, Android developers will accomplish the following:

  • View the complete and comparative size of the APK.
  • Know the composition of DEX files.
  • Fast view of the final versions of files in the APK, such as the AndroidManifest.xml file.
  • Conduct a side-by-side comparison of two APKs.

4. Image Optimization

Higher resolution images are always the best and first choice for attracting users towards the website. Since the latest mobile device comes with a good camera resolution, the image size might as well be reduced by diluting the resolution. In case, you don’t want to lose your image quality, then you have to convert you’re .jpg or .png images to .webp.

Utilizing images without reducing the size may effect the app quality. Rather than uploading or using the original image in you’re app, convert you’re .jpg and .png images to web format. For png files, you can also use tools like pngcrush or Zopflipng. For jpg files, you can use tools like packJPG and Guetzli. You can also use vector graphics as it makes an image simple and utilizes space.

android {    
defaultConfig {
vectorDrawables.useSupportLibrary true
}
}

It is a fact that images can do wonders without static resources. At runtime, the framework is sufficient to draw such images dynamically. Besides, using the Vector Drawables objects is a great idea when small-sized apps are created.

As these apps can survive in minimal space within the APK file and create pictures compliant with material design rules, using Vector Drawables is valuable. One should also take care about the tussle that could arise concerning CPU and RAM usage as complex objects.

5. Support for Specific Screen Densities

To reduce the Android App Size, utilizing specific screen densities in the right way is another great option. their are a million Android-enabled devices with varied screen densities. Yet, we don’t use entire screen densities and can eliminate which is not required.

To destroy bundling all unused screen densities into you’re app, analyze to determine the % of users with devices that has specific densities. If this % ratio is insignificant, you has a reason to eliminate them and lighten you’re app size.

6. Removing Dead Code

The size of the APK file is directly related to the load speed of your app, and the memory it occupies and the power it consumes. So, any unused or inappropriate code kept for the sake of keeping would only add to the junk. This is why the removal of dead code or code elimination is required for your app to stay active and energized all time, all day.

This code removal will enhance the quality of source code and lower the need to maintain code size, thus manifesting a healthy app, overall.

7. Reuse Your Resource

Reusing is rally better and simpler TEMPthan removal. It’s an amazing way to utilize you’re resources in various manners. It gives you a smooth scrolling performance. It can help you reduce the final size of you’re Android APK. You can eliminate those resources that are only a rotated equivalent of another resource.

Suppose, you may have tactful resources to characterize varieties in an image pertaining to tints, shades and direction. However, you could utilize the same resources for other images.

8. Multiple APK Files Support

Some APKs consist of content that gets downloaded but is barely ever utilized. For example, add-ons like additional languages are not always needed, however, are downloaded anyhow. this occupies the additional spaces in your storage and enlarges the app.

However, this trouble has made the developer’s mind work towards better solutions to download only certain parts of an app beneficial to the users. Unfortunately, it’s not possible to download a useful part of an APK.

But to make it work nearer to these solutions, you can upload the app over the Google Play store via the Android App Bundle which allows Google to enable optimized APKs on the basis of device configuration. For this, you can divide one app into multiple APKs. After this, users can get only those APKs that are beneficial for them as per their device configuration.

9. Avoid Enumerations

Enums are dubious. A single one can be easily added anywhere in the range from 1.0 to 1.4 KB to the classes.dex file of an application. These can consume a whole lot of high speed if there are complex frameworks or shared libraries.

So, how can you overcome this problem? Well, with the use of ProGuard, you can convert the enums into integers and the end result is a reduced-size app.

Commands

  • flutter build apk — analyze-size
  • flutter build appbundle — analyze-size
  • flutter build ios — analyze-size

That’s all for today. Thanks for staying until the end. I believe these projects will help you learn a lot of new things.

For more interesting content you can follow me here

https://www.linkedin.com/in/ariba1039/

https://twitter.com/ariba_hussain10

--

--

ariba.dev
ariba.dev

Written by ariba.dev

⚡Dart makes my heart Flutter 💙🧑‍💻 • ✨ Software developer🧑‍💻 • Looking for the best remote opportunity in EUROPE

Responses (1)