Home > Enterprise >  How to decrease flutter app size in android
How to decrease flutter app size in android

Time:12-21

I make my app using flutter and my app size is more than 100 mb and app has 15 screens.

It's android size is more than 100 mb and iOS app size is 40 mb I have to make it small and I want proper solution for this



I try to compress my image files but it just decrease 8 mb

I want proper solution for compress flutter app size.

CodePudding user response:

  1. How many third-party packages are you using?

  2. Did you use drag and drop to create the app or code everything manually?

  3. Did you properly use const in objects that are repeated but are essentially the same? Like const EdgeInsets.all(8.0).

  4. Do you have a lot of gradient images that you can convert to Container gradients?

CodePudding user response:

  1. Use webp images instead of PNG or JPEG
  2. Add pro-guard files
  3. Minify Enabled - true
  4. Shrink- Resource -true

CodePudding user response:

try running:

flutter clean

and then:

flutter build apk --split-per-abi

you could even further reduce the size of your code by doing:

flutter build apk --split-debug-info=/<project-name>/<directory>

and if you're willing to take the risk, you can obfuscate your code:

flutter build apk --obfuscate --split-debug-info=/<project-name>/<directory>

where

/<'project-name'>/<'directory'>

is the directory where Flutter can output your app debug files.

CodePudding user response:

Check this below steps it may help you to reduce app size (only Android), i have reduced my 48mb build to 14mb

Step 1: android/gradle.properties android.enableR8=true

Step 2: android/app/build.gradle

inside -> buildTypes -> release

minifyEnabled true
shrinkResources true
useProguard true

Step 3:

Run

flutter build apk --target-platform=android-arm

or

flutter build apk --split-per-abi

Some other optimizing tips,

1. Image assets

Upload the images in permanent storage path like AWS or in your website server and use the link to that image in your code.

2. Icons

Its recommended to use from Material Icons or Cupertino Icons class. You can add --tree-shake-icons option to flutter build command, to remove all of the not used icons from the bundle. This will potentially save the size of your app. (use svg format icons)

3. Fonts

If we are using more fonts from local assets similar like images these fonts will also increase app size. The best solution is to use google_fonts plugin. This pluign will dynamically download font when it is used.

4. Dynamic App Delivery

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. By using appbundle Google Play’s new app serving model, called Dynamic Delivery, uses your app bundle to generate and serve optimized APKs for each user’s device configuration, so they download only the code and resources they need to run your app.

Refer below links for more understanding,

  1. https://developer.android.com/studio/build/shrink-code
  2. https://developer.android.com/guide/app-bundle
  3. https://www.youtube.com/watch?v=9D63S4ZRBls
  • Related