flutter_soloud icon indicating copy to clipboard operation
flutter_soloud copied to clipboard

fix: dlopen failed: library "libflutter_soloud_plugin.so" not found

Open oremlawi opened this issue 3 months ago • 12 comments

Description My app uses flutter_soloud: ^3.1.3 and all good until I upgraded to 3.3.7 in order to fix the 16 KB page size support issue, but I've noticed that it doesn't work on release mode, only debug mode can run the app.

Error logs This is the error shows up when I run on release mode:

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libflutter_soloud_plugin.so': dlopen failed: library "libflutter_soloud_plugin.so" not found E/flutter (25336): #0 open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11) E/flutter (25336): #1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22) E/flutter (25336): #2 new SoLoudController. (package:flutter_soloud/src/bindings/soloud_controller_ffi.dart:17) E/flutter (25336): #3 new SoLoudController (package:flutter_soloud/src/bindings/soloud_controller_ffi.dart:10) E/flutter (25336): #4 new SoLoud._ (package:flutter_soloud/src/soloud.dart:77) E/flutter (25336): #5 SoLoud.instance (package:flutter_soloud/src/soloud.dart:169) ... Application finished.

Steps To Reproduce Run with --release argument

oremlawi avatar Oct 06 '25 10:10 oremlawi

Hi @oremlawi, I've tried to run some examples on some physical devices in release mode, but I didn't get your issue.

May I suggest you to try to run flutter clean and then ./gradlew clean within the android dir?

Your error message states that the libflutter_soloud_plugin.so has not been found (not generated because a compiler error?). This means that some other error appeared before the one you posted?

alnitak avatar Oct 06 '25 12:10 alnitak

Hi @alnitak, thanks for your reply. Indeed I've already did that. But I repeated what you're suggesting, and the error still there for some reason.

I'm using ndkVersion = "27.0.12077973" along with targetSdkVersion 35. Also tried VERSION_17 and VERSION_19 and the result still the same.

oremlawi avatar Oct 06 '25 14:10 oremlawi

This means that some other error appeared before the one you posted?

This is the first received log right before the error (above) was reported, nothing before: [IMPORTANT:flutter/shell/platform/android/android_context_vk_impeller.cc(61)] Using the Impeller rendering backend (Vulkan).

Does it make any sense?

oremlawi avatar Oct 06 '25 14:10 oremlawi

Does it make any sense?

Unfortunately no. That's only to inform you about the use of Impeller, which is the new graphics engine.

Could you please try running the main.dart example of the plugin? Clone this repo, then go into exampledir and run:

flutter run -t lib/main.dart --release --verbose

with the --verbose flag, you should see more info. Maybe, before trying to clone this, you can try with your code. This is just to be sure that no other dependencies influence the result.

alnitak avatar Oct 06 '25 15:10 alnitak

The example doesn't work, even after some fixes to make it build, but since the AndroidManifest.xml is empty all other fixes didn't work. However when I ran flutter run -t lib/main.dart --release --verbose in my code, nothing relevant came up.

But check this, maybe this is relevant:

[        ] Caching disabled for task ':flutter_soloud:mapReleaseSourceSetPaths' because:
[        ]   Build cache is disabled
[        ]   Caching has been disabled for the task
[        ] Skipping task ':flutter_soloud:mapReleaseSourceSetPaths' as it is up-to-date.
[        ] Resolve mutations for :flutter_soloud:mergeReleaseResources (Thread[#345,Execution worker Thread 4,5,main]) started.
[        ] :flutter_soloud:mergeReleaseResources (Thread[#345,Execution worker Thread 4,5,main]) started.
[        ] > Task :flutter_soloud:mergeReleaseResources UP-TO-DATE
[        ] Caching disabled for task ':flutter_soloud:mergeReleaseResources' because:
[        ]   Build cache is disabled
[        ] Skipping task ':flutter_soloud:mergeReleaseResources' as it is up-to-date.
[        ] Resolve mutations for :flutter_soloud:verifyReleaseResources (Thread[#345,Execution worker Thread 4,5,main]) started.
[        ] :flutter_soloud:verifyReleaseResources (Thread[#345,Execution worker Thread 4,5,main]) started.
[        ] > Task :flutter_soloud:verifyReleaseResources UP-TO-DATE
[        ] Transforming aapt2-8.8.2-12006047-osx.jar (com.android.tools.build:aapt2:8.8.2-12006047) with Aapt2Extractor
[        ] Transforming fragment-1.7.1.aar (androidx.fragment:fragment:1.7.1) with JetifyTransform
[        ] Transforming fragment-1.7.1.aar (androidx.fragment:fragment:1.7.1) with ExtractAarTransform
[        ] Transforming fragment-1.7.1.aar (androidx.fragment:fragment:1.7.1) with AarResourcesCompilerTransform


[        ] Caching disabled for task ':flutter_soloud:verifyReleaseResources' because:
[        ]   Build cache is disabled
[        ] Skipping task ':flutter_soloud:verifyReleaseResources' as it is up-to-date.
[        ] Resolve mutations for :flutter_soloud:assembleRelease (Thread[#345,Execution worker Thread 4,5,main]) started.
[        ] :flutter_soloud:assembleRelease (Thread[#344,Execution worker Thread 3,5,main]) started.
[        ] > Task :flutter_soloud:assembleRelease UP-TO-DATE
[        ] Skipping task ':flutter_soloud:assembleRelease' as it has no actions.

oremlawi avatar Oct 06 '25 16:10 oremlawi

Unfortunately that log doesn't tell me much! I don't know why I am not getting this and as far as I understand, this happens only in release mode. But there are few things we could try to figure out:

  1. Check if the libflutter_soloud_plugin.so has been compiled. Try to look in build/<your_app_nam>/intermediates/merged_native_libs/release/out/lib/ in all the architecture dirs if the lib exists. If it doesn't exist, it is not compiled ( improbable since there are no error logs) or it is stripped out (maybe you haven't used yet any flutter_soloud code in your app?)
  2. try to add in your app/src/build.gradle.kts:
buildTypes {
    release {
        shrinkResources false
        minifyEnabled false
        ...

alnitak avatar Oct 06 '25 17:10 alnitak

Apparently it is not exist (please check the attached image). And regarding the point 2, also the same.

Image

oremlawi avatar Oct 07 '25 08:10 oremlawi

By the way, in regards of 16 KB page size support, it is recommended to be on NDK r28+, while currently flutter_soloud still on r27. So when I try to build using ndkVersion = "29.0.14033849" I get this error:

[   +1 ms] FAILURE: Build failed with an exception.
[        ] * What went wrong:
[        ] A problem occurred configuring project ':flutter_soloud'.
[        ] > [CXX1104] NDK from ndk.dir at /Users/myUser/Library/Android/sdk/ndk/29.0.14033849 had version [29.0.14033849] which disagrees with android.ndkVersion [27.0.12077973]

So what I've done is to host flutter_soloud locally, and changed the ndkVersion like this (from build.gradle):

    // ndkVersion = android.ndkVersion
    ndkVersion = "29.0.14033849"

And the bug is fixed. But I had to downgrade my Flutter version from 3.32.8 down until 2.29.0 to eliminate some breaking codes inside these 2 files:

  1. filters/filters.dart
  2. bindings/audio_data.dart

So I think whoever has a recent Flutter version will face the same issue, and the fix is to upgrade the NDK version.

Here is the new folder structure after applying the above fix:

Image

oremlawi avatar Oct 07 '25 08:10 oremlawi

Good point! But I still can't figure out why you don't see any compiling errors.

flutter_soloud does use the Flutter android.ndkVersion as you can see here. Since you have cloned the plugin, can you please try to change that line to ndkVersion = "27.0.12077973"?

alnitak avatar Oct 07 '25 09:10 alnitak

You're right, it is not clear why. However when I explicitly use ndkVersion = "27.0.12077973" It clashes as in my code I use ndkVersion = "29.0.14033849", so it never builds because of this:

[   +1 ms] FAILURE: Build failed with an exception.
[        ] * What went wrong:
[        ] A problem occurred configuring project ':flutter_soloud'.
[        ] > [CXX1104] NDK from ndk.dir at /Users/myUser/Library/Android/sdk/ndk/29.0.14033849 had version [29.0.14033849] which disagrees with android.ndkVersion [27.0.12077973]

oremlawi avatar Oct 07 '25 09:10 oremlawi

I remember that there were some errors when using NDK 29, but I just tried setting 29 in both plugin and example gradle, and it compiles fine!

I also see that the flutter.ndkVersion is set to "27.0.12077973" (<flutter_sdk>/packages/flutter_tools/gradle/src/main/kotlin/FlutterExtension.kt).

Also, even after a clean, I don't see any C source compiler logs. I see it only if I write something wrong in some C sources to force some errors!

I am trying with a Samsung Galaxy with Android 15 (SDK 35) and Flutter 3.35.4 in release mode.

Please give me some more time to figure out what's happening even if I cannot reproduce this issue, but if you find something new, please let me know.

alnitak avatar Oct 07 '25 10:10 alnitak

Sure, please take your time.

Your support is appreciated.

oremlawi avatar Oct 07 '25 10:10 oremlawi