Home > Enterprise >  The Flutter app size is so big. How to reduce it?
The Flutter app size is so big. How to reduce it?

Time:01-22

Its starting app size is 17 MB. When developing the app, It's increasing the size from 17MB. How to reduce the size of flutter given app (First project)

I used this method to get android app

flutter build apk --build-name=0.1 --build-number=2

CodePudding user response:

According to the Official documentation of Flutter, they have various steps to analyze which part of your code is exactly taking much more space than needed.

They have a proper guide on that, to take you through analyzing the source code, testing the app size, and giving you the information of which file or dependency is taking more size and how much it is taking.

If you don't want to go through it, here are some common things by which it can reduce your app size.

  1. Remove unused resources
  2. Minimize resources imported from libraries
  3. Compress PNG and JPEG files

Here's the official documentation if you want to read it.

Documentation Link

CodePudding user response:

There are several ways to reduce the size of a Flutter app:

  • Remove unused assets: Make sure you're only including assets that are actually being used in your app. You can use a tool like flutter clean to remove any unused assets.

    Use smaller image sizes: Use smaller image sizes wherever possible, especially for images that are used as background images or icons. You can use tools like image_optim to optimize the image size.

    Use dynamic linking for iOS: Dynamic linking can significantly reduce the size of your iOS app. By default, Flutter apps use static linking, which includes all of the Dart code in the app bundle. Dynamic linking, on the other hand, only includes the Dart code that is actually used by the app.

    Remove unnecessary plugins: Make sure you're only using plugins that are necessary for your app. You can use a tool like flutter doctor --verbose to see a list of all the plugins that are currently being used by your app.

    Use Proguard for Android: Proguard is a code obfuscator for Android that can significantly reduce the size of your app. You can enable Proguard in your android/app/build.gradle file by adding the following code:

android {
    buildTypes {
        release {
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

  • Use App Thinning: App Thinning is an iOS feature that allows you to reduce the size of your app by only including the resources that are needed for the specific device on which the app is installed.

    Use Dart's tree shaking: Dart's tree shaking feature can help you remove any unnecessary code that is not being used by the app.

    It's important to note that not all of these methods will be appropriate for every app, and the best approach will depend on the specifics of your app. Additionally, you may need to test on different devices to see the real impact of these optimization methods.

CodePudding user response:

you can try the following

  1. Compress PNG and JPEG files
  2. reduce the use of container and replace them with SizedBox and Cards
  3. Minimize resource imported from libraries
  4. Remove unused resources
  5. the fewer the screens the better

also you can split the apks while building it using this command

**flutter build apk --target-platform android-arm,android-arm64 --split-per-abi **

and always

  • Related