Setting minSdkVersion >22 more than twofold increases apk size

Details

I came across this problem when I had to increase minSdkVersion to 23. The apk size jump from ~5.5Mb to ~12Mb. The most vulnerable part of apk is the Flutter Engine (libflutter.so) it changes from 4Mb(minSdkVersion<=22) to 8.6Mb(minSdkVersion>=23). Somehow I thought that the apk size should decrease with increasing minSdkVersion.

Target Platform: Android

flutter doctor -v
[✓] Flutter (Channel stable, 2.0.3, on Linux, locale en_CA.UTF-8)
    • Flutter version 2.0.3 at /home/yuri/snap/flutter/common/flutter
    • Framework revision 4d7946a68d (2 weeks ago), 2021-03-18 17:24:33 -0700
    • Engine revision 3459eb2436
    • Dart version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/yuri/Android/Sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /home/yuri/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Android Studio
    • Android Studio at /home/yuri/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] IntelliJ IDEA Ultimate Edition (version 2020.3)
    • IntelliJ at /snap/intellij-idea-ultimate/285
    • Flutter plugin version 55.0.4
    • Dart plugin version 203.7759

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.90

• No issues found!

I checked this issue by creating a new empty Flutter project in Android Studio. I built apk for the arm64 platform.
flutter build apk --analyze-size --target-platform android-arm64

minSdkVersion = 16
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Running Gradle task 'assembleRelease'...                                
Running Gradle task 'assembleRelease'... Done                      26.4s
✓ Built build/app/outputs/flutter-apk/app-release.apk (5.5MB).
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
app-release.apk (total compressed)                                          5 MB
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  res/
    mipmap-xxxhdpi-v4                                                       1 KB
  lib/
    arm64-v8a                                                               5 MB
    Dart AOT symbols accounted decompressed size                            3 MB
      package:flutter                                                       2 MB
      dart:core                                                           307 KB
      dart:typed_data                                                     217 KB
      dart:ui                                                             188 KB
      dart:async                                                          114 KB
      dart:collection                                                     111 KB
      dart:convert                                                         58 KB
      dart:isolate                                                         38 KB
      dart:io                                                              38 KB
      package:vector_math                                                  30 KB
      dart:developer                                                       10 KB
      package:typed_data/
        src/
          typed_buffer.dart                                                 7 KB
      package:collection/
        src/
          priority_queue.dart                                               5 KB
      dart:math                                                             4 KB
      dart:ffi                                                              4 KB
      package:flutter_app2/
        main.dart                                                           3 KB
      dart:vmservice_io                                                     2 KB
      dart:mirrors                                                         697 B
      dart:nativewrappers                                                  383 B
      Never                                                                 63 B
  META-INF/
    MANIFEST.MF                                                             2 KB
    CERT.SF                                                                 3 KB
    kotlin-stdlib.kotlin_module                                             1 KB
    CERT.RSA                                                              1012 B
  assets/
    flutter_assets                                                        184 KB
  kotlin/
    reflect                                                                 2 KB
    collections                                                             1 KB
    kotlin.kotlin_builtins                                                  4 KB
  resources.arsc                                                           23 KB
  AndroidManifest.xml                                                     1016 B
  classes.dex                                                             120 KB
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
A summary of your APK analysis can be found at: /home/yuri/.flutter-devtools/apk-code-size-analysis_24.json

To analyze your app size in Dart DevTools, run the following command:
flutter pub global activate devtools; flutter pub global run devtools --appSizeBase=apk-code-size-analysis_24.json
minSdkVersion = 22
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Running Gradle task 'assembleRelease'...                                
Running Gradle task 'assembleRelease'... Done                      24.8s
✓ Built build/app/outputs/flutter-apk/app-release.apk (5.5MB).
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
app-release.apk (total compressed)                                          5 MB
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  res/
    mipmap-xxxhdpi-v4                                                       1 KB
  lib/
    arm64-v8a                                                               5 MB
    Dart AOT symbols accounted decompressed size                            3 MB
      package:flutter                                                       2 MB
      dart:core                                                           307 KB
      dart:typed_data                                                     217 KB
      dart:ui                                                             188 KB
      dart:async                                                          114 KB
      dart:collection                                                     111 KB
      dart:convert                                                         58 KB
      dart:isolate                                                         38 KB
      dart:io                                                              38 KB
      package:vector_math                                                  30 KB
      dart:developer                                                       10 KB
      package:typed_data/
        src/
          typed_buffer.dart                                                 7 KB
      package:collection/
        src/
          priority_queue.dart                                               5 KB
      dart:math                                                             4 KB
      dart:ffi                                                              4 KB
      package:flutter_app2/
        main.dart                                                           3 KB
      dart:vmservice_io                                                     2 KB
      dart:mirrors                                                         697 B
      dart:nativewrappers                                                  383 B
      Never                                                                 63 B
  META-INF/
    MANIFEST.MF                                                             2 KB
    CERT.SF                                                                 3 KB
    kotlin-stdlib.kotlin_module                                             1 KB
    CERT.RSA                                                              1020 B
  assets/
    flutter_assets                                                        184 KB
  kotlin/
    reflect                                                                 2 KB
    collections                                                             1 KB
    kotlin.kotlin_builtins                                                  4 KB
  resources.arsc                                                           21 KB
  AndroidManifest.xml                                                     1016 B
  classes.dex                                                             120 KB
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
A summary of your APK analysis can be found at: /home/yuri/.flutter-devtools/apk-code-size-analysis_26.json

To analyze your app size in Dart DevTools, run the following command:
flutter pub global activate devtools; flutter pub global run devtools --appSizeBase=apk-code-size-analysis_26.json
minSdkVersion = 23
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Running Gradle task 'assembleRelease'...                                
Running Gradle task 'assembleRelease'... Done                      23.2s
✓ Built build/app/outputs/flutter-apk/app-release.apk (12.0MB).
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
app-release.apk (total compressed)                                         12 MB
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  res/
    mipmap-xxxhdpi-v4                                                       1 KB
  lib/
    arm64-v8a                                                              12 MB
    Dart AOT symbols accounted decompressed size                            3 MB
      package:flutter                                                       2 MB
      dart:core                                                           307 KB
      dart:typed_data                                                     217 KB
      dart:ui                                                             188 KB
      dart:async                                                          114 KB
      dart:collection                                                     111 KB
      dart:convert                                                         58 KB
      dart:isolate                                                         38 KB
      dart:io                                                              38 KB
      package:vector_math                                                  30 KB
      dart:developer                                                       10 KB
      package:typed_data/
        src/
          typed_buffer.dart                                                 7 KB
      package:collection/
        src/
          priority_queue.dart                                               5 KB
      dart:math                                                             4 KB
      dart:ffi                                                              4 KB
      package:flutter_app2/
        main.dart                                                           3 KB
      dart:vmservice_io                                                     2 KB
      dart:mirrors                                                         697 B
      dart:nativewrappers                                                  383 B
      Never                                                                 63 B
  META-INF/
    MANIFEST.MF                                                             2 KB
    CERT.SF                                                                 3 KB
    kotlin-stdlib.kotlin_module                                             1 KB
    CERT.RSA                                                              1019 B
  assets/
    flutter_assets                                                        184 KB
  kotlin/
    reflect                                                                 2 KB
    collections                                                             1 KB
    kotlin.kotlin_builtins                                                  4 KB
  resources.arsc                                                           21 KB
  AndroidManifest.xml                                                       1 KB
  classes.dex                                                             120 KB
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
A summary of your APK analysis can be found at: /home/yuri/.flutter-devtools/apk-code-size-analysis_25.json

To analyze your app size in Dart DevTools, run the following command:
flutter pub global activate devtools; flutter pub global run devtools --appSizeBase=apk-code-size-analysis_25.json

1 possible answer(s) on “Setting minSdkVersion >22 more than twofold increases apk size