Flutter abiFilters not generating libflutter.so for all architecture
Asked Answered
S

6

5

In my Flutter application I am trying to generate apk that should work on all the devices whether it is 32 bit or 64 bit.

For that I have put the following lines in my build.gradle file. But it looks like it is not generating the libflutter.so for all the architectures.

    android {
       compileSdkVersion 27
       defaultConfig {
           appId "com.google.example.64bit"
           minSdkVersion 15
           targetSdkVersion 28
           versionCode 1
           versionName "1.0"
           ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'

As we can see in the below image the libflutter.so is present only in armeabi-v7a and all other folder are missing it. This issue crashes my app on startup when I release it on Google Play.

  Exceptions
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/abc.xyz.idar-1/base.apk"],nativeLibraryDirectories=[/data/app/abc.xyz.idar-1/lib/arm64, /data/app/abc.xyz.idar-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/lib64]]] couldn't find "libflutter.so"

enter image description here

I am using flutter build apk command to generate the apk.

Samale answered 24/4, 2019 at 12:37 Comment(0)
I
4

I've been struggling for this issue for more than a month. Finally flutter has released a so called PATCH in manner to support the 64 bit application building support.

To build the application by their architecture use flutter SDK version 1.7.4 or greater. Its still in dev channel but things are working as expected. Here is the link to download the SDK

Now lets come to main code where all magic happens:

DO NOT INCLUDE ANY ABI FILTERS IN YOUR GRADLE FILE TO GENERATE THE SPLIT APKs

defaultConfig {
    applicationId "YOUR.PACKAGE.NAME"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
    release {
        signingConfig signingConfigs.debug
        minifyEnabled false
    }
}

Now open terminal and use this command on your root directory to generate the Apks

\\PATH_TO_YOUR_FLUTTER_SDK_DIR\bin\flutter build apk --split-per-abi

For example in my case:

D:\flutter_windows_v1.2.1-stable\flutter_v1.7.4-dev\flutter\bin\flutter build apk --split-per-abi

Well it will take pretty long time to generate, but it worth and works lol... here is some output logs for just reference.

Running Gradle task 'assembleRelease'... Done                     139.7s (!)
Built build\app\outputs\apk\release\app-armeabi-v7a-release.apk (10.0MB).
Built build\app\outputs\apk\release\app-arm64-v8a-release.apk (10.3MB).
Inaction answered 17/6, 2019 at 5:46 Comment(3)
Working good with 1.7.4, thanks for the update man. saved the dayRivy
painting.dart:1657:15: Context: Found this candidate, but the arguments don't match. it gives me error :(Jesuit
Do you have a fix that fixes play store app bundle?Aerodrome
C
3

This is a currently known issue in Flutter repository. I hope they are able to fix this soon.

https://github.com/flutter/flutter/issues/18494.

I found the best work around is to follow this comment.

When you run flutter build apk, this work around will remove all resources in 64-bit folders. Thus, the 64-bit device will only use resources in 32-bit folder.

Clareclarence answered 25/4, 2019 at 0:14 Comment(7)
Do I need to generate and upload two APKs? One for arm64-v8a and other for armeabi-v7a? When I did flutter build apk it generated apk with armeabi-v7a only.Samale
@Sam, No for now. But Yes from August 2019, Google requires APK to have 64-bit support. So from that time, you need to generate two APKs: 32-bit, and 64-bit, and upload 2 APKs to Google store. You can also generate one AAB (Android app bundle) flutter build appbundle, and upload that to Google store. But, I don't know if the later option really works for Flutter.Clareclarence
thanks for your time and help. My app is not crashing now. Hope they will fix the issue in the near future as I can see it is not assigned to anyone :-)Samale
some user reported the app is still crashing on their mobile. I think it is 86 bit device. Do you know what can be done?Samale
@Sam: Did you find the solution. I need to generate x86 architecture app but it keep crashing because of missing libflutter.soGabe
@MunishThakur I switched to stable channel of flutter and upgrade all my packages. Then it started working.Samale
@Sam: Which flutter version you are on? I will use that only.Gabe
C
1

Upgarde/Switch to flutter master channel (if you aren't using it). The issue is resolved by Flutter team. Now, a single command flutter build apk will produce the apk compatible with both 32-bit and 64-bit architecture.

Carboy answered 20/6, 2019 at 14:2 Comment(4)
I am using Android Studio on Windows machine. How can I upgrade/switch to the master channel. Also this command will produce the single apk that I can upload at once?Samale
Yes, this command will produce a single APK file. Use command "flutter channel master" to switch. For upgrade, it's "flutter upgrade"Carboy
I switched to master channel and upgrade the flutter. Then I tried the command but it is still not creating the libflutter.so file for other architecture. I can find it only under armeabi-v7a and that is why the app crashes on startup.Samale
Please run "flutter clean" to clean the build and try again.Carboy
C
0

Change your build.gradle like so

android {
   compileSdkVersion 27
   defaultConfig {
      // Remove ndk.abiFilters from here
   }

   buildTypes {
       release {
           ndk.abiFilters 'armeabi-v7a'
       }
   }

That is what I use to release on Google Play and I haven't got any issue so far.

Condition answered 24/4, 2019 at 12:46 Comment(6)
When I put the release block inside the android block the gradle build fails when I run flutter build apk. A problem occurred evaluating project ':app'. > Could not find method release() for arguments [build_7ydgmn6mc1qqyegyvt3fid2vs$_run_closure2$_closure7@44a36f4c] on object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.Samale
@Samale I updated the answer. Release needs to be nested inside buildTypesCondition
I tried that but it is still not creating the libflutter.so in any folder except armeabi-v7a.Samale
That is totally fine. Just one lib folder (armeabi-v7a) which will make the apk compatible with 32 and 64 bit architectures.Condition
What about x86_64 and x86? will it crash there?Samale
@Samale I haven't experienced any crashes on my app users. Check out this comment from the Flutter website flutter.dev/docs/resources/…Condition
I
0

You can try this command to build 64-bit apk

flutter build apk --release --target-platform=android-arm64
Innermost answered 23/5, 2019 at 8:27 Comment(0)
M
0

In your build.gradle inside defaultConfig add this:

ndk {
    abiFilters "armeabi", "x86", "armeabi-v7a"
}

Run flutter build apk --release

Send apk file to Play store.

Mattiematting answered 16/6, 2019 at 20:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.