Search code examples
flutterdartapk

Could not find an option named "split-per-abi"


Please what version of flutter support the --split-per-abi option when building an APK file with flutter build apk. I am making use of Flutter 1.5.4-hotfix.2 and still can't access that option.
According to the documentation Preparing an Android app for release,

This command results in two APK files:

<app dir>/build/app/outputs/apk/release/app-armeabi-v7a-release.apk
<app dir>/build/app/outputs/apk/release/app-arm64-v8a-release.apk

Removing the --split-per-abi flag results in a fat APK that contains your code compiled for all the target ABIs. Such APKs are larger in size than their split counterparts, causing the user to download native binaries that are not applicable to their device’s architecture.

How can I make it work?

EDIT: It works on Flutter 1.7.4


Solution

  • In your <app dir>/android/app/build.gradle add a splits section as described here: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split

    A basic configuration would be to add this to your build.gradle

    android {
      ...
      splits {
    
        // Configures multiple APKs based on ABI.
        abi {
    
          // Enables building multiple APKs per ABI.
          enable true
    
          // By default all ABIs are included, so use reset() and include to specify that we only
          // want APKs for x86 and x86_64.
    
          // Resets the list of ABIs that Gradle should create APKs for to none.
          reset()
    
          // Specifies a list of ABIs that Gradle should create APKs for.
          include "x86", "x86_64", "armeabi", "armeabi-v7a", "arm64-v8a"
    
          // Specifies that we do not want to also generate a universal APK that includes all ABIs.
          universalApk false
        }
      }
    }
    

    Then just run the command as the documentation says:

    flutter build apk --split-per-abi
    

    Here is the list of supported ABIs: https://developer.android.com/ndk/guides/abis.html#sa

    With the config above you should get all supported ABIs

    enter image description here