0

We are using a number of firebase plugins

  cloud_firestore: ^2.5.1
  firebase_analytics: ^8.3.1
  firebase_auth: ^3.1.0
  firebase_core: ^1.6.0
  firebase_remote_config: ^0.11.0
  flutter_facebook_auth: ^3.5.1
  google_sign_in: ^5.0.4

The size of the release APK seems to have drastically increased. Before it would create APKs of ~9MB with,

$ flutter build apk --split-per-abi

Now the generated APKs are ~20MB each!
I have tried running flutter clean and rebuilding the release APKs, yet the APKs are having the same size.

What could be causing this issue? And how to resolve this?

P.S. we need all those plugins

Nithin Sai
  • 840
  • 1
  • 10
  • 23
  • 3
    I believe that is a reasonable size considering blank project with only hello world is approx 5MB(https://stackoverflow.com/questions/49064969/flutter-apps-are-too-big-in-size look at the accepted answer). So that leaves your code, package code and assets left at 15MB which is not too big. I would suggest you look at your assets and build aab file which almost halves the production size of an app. Also you can check this [link](https://developer.android.com/topic/performance/reduce-apk-size) – igorkrz Oct 01 '21 at 16:37

1 Answers1

2

You can use code minify and obfuscation to make the APK smaller by adding these configs to your build.gradle (app-level) file

    android {
    buildTypes {
        release {
            // Enables code shrinking, obfuscation, and optimization for only
            // your project's release build type.
            minifyEnabled true

            // Enables resource shrinking, which is performed by the
            // Android Gradle plugin.
            shrinkResources true

            // Includes the default ProGuard rules files that are packaged with
            // the Android Gradle plugin. To learn more, go to the section about
            // R8 configuration files.
            proguardFiles getDefaultProguardFile(
                    'proguard-android-optimize.txt'),
                    'proguard-rules.pro'
        }
    }
}

It will remove the methods of libraries which are not used by your code. And obfuscates, i.e: shrinks the codebase by replacing variable/method/class names with smallest possible names. And it will be protection against reverse engineering as well.

  • Hey, with the new code added, the release APK is now ~15MB! Is this the least it can go? Thanks btw! – Nithin Sai Oct 01 '21 at 17:01
  • It's possible to shrink more with more detailed ProGuard rules. With ProGuard rules you can manage how is obfuscating and deleting process works. The code above shrinks your code in default way. And since it is the default way, maybe there is a unused codes in libraries still. – Abdulaziz Abduqodirov Oct 01 '21 at 20:42