skip to Main Content

I recently added the following packages to my Flutter project:

dependencies:
  sqflite: ^2.3.2
  path: ^1.8.3

Since adding these packages, I’ve noticed that my APK size has increased by approximately 100 MB, bringing the total size to around 200 MB. This is a significant increase, and I’m concerned about the impact on app performance and user experience.

What I Have Tried:

  1. Run flutter clean: Cleared build artifacts and cached files.

  2. Clear Flutter and Gradle Cache: Used flutter pub cache repair and deleted .gradle caches.

  3. Analyze APK Size: Attempted to analyze the APK size but faced issues with specifying a single ABI.

Questions:

  1. Is it common for the sqflite and path packages to cause such a large increase in APK size?

  2. What are the possible reasons for this substantial size increase after adding these packages?

  3. What additional steps can I take to further investigate and reduce the APK size?

Any guidance or suggestions on how to resolve this issue would be greatly appreciated.

Thank you!

2

Answers


  1. I am not sure about sqflite and path. But here are some tips to cretae apk a bit lighter.

    1. flutter clean
    2. flutter pub get
    3. flutter build apk –release
      this will create apk in release.
      I hope this work for you.
    Login or Signup to reply.
  2. To decrease the size of an APK in a Flutter app, follow these steps:

    1. Remove Unused Dependencies

    • Analyze your pubspec.yaml file and remove any unused dependencies. Every additional package adds code to your APK.

    2. Enable ProGuard for Android

    • ProGuard helps shrink, optimize, and obfuscate your code. To enable ProGuard:
      • In android/app/build.gradle, set the minifyEnabled option to true for the release build type:
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        

    3. Shrink Resources

    • You can also enable shrinking of unused resources by adding the following to the release block in build.gradle:
      buildTypes {
          release {
              shrinkResources true
              minifyEnabled true
          }
      }
      

    4. Use Split APKs by ABI

    • Flutter builds a fat APK by default, which contains binaries for multiple architectures (ARMv7, ARM64, x86). You can reduce APK size by generating separate APKs for each ABI:
      flutter build apk --split-per-abi
      
    • This will generate multiple APKs (e.g., app-armeabi-v7a-release.apk, app-arm64-v8a-release.apk, etc.).

    5. Remove Debugging Information

    • Ensure you’re building in release mode:
      flutter build apk --release
      

    6. Use Flutter Build for Tree Shaking Icons

    • Remove unused icons by tree-shaking material icons:
      flutter build apk --release --tree-shake-icons
      

    7. Optimize Images

    • Compress your image assets using tools like TinyPNG or ImageOptim.
    • Use appropriate image formats such as WebP, which offers good compression.

    8. Avoid Using Large Fonts

    • If you’re embedding custom fonts, ensure you’re not including large fonts that may not be used in your app.

    9. Use R8 Instead of ProGuard

    • R8 is enabled by default in newer versions of Android Studio. It’s faster and more efficient than ProGuard. Just ensure you have it set up properly:
      buildTypes {
          release {
              shrinkResources true
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
      

    By following these steps, you can reduce the size of your Flutter APK efficiently.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search