Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flutter] [Android] Failed to load dynamic library 'libmmkv.so': dlopen failed: library "libmmkv.so" not found #1321

Closed
T-moz opened this issue Jun 3, 2024 · 8 comments

Comments

@T-moz
Copy link

T-moz commented Jun 3, 2024

Java & Dart

Version 1.3.5

Also reproduced on main.

The platform of MMKV

Flutter Android

The installation of MMKV

Pub dev

What's the issue?

image

When calling MMKV initialise on an Samsung J3, DynamicLibrary.open('libmmkv.so') throw.

I've reproduced this issue when running the flutter exemple app from MMKV repo.

This issues seems to appears only on a few old devices.
Here is a non exhaustive list of devices.

Brand Model Android version
Samsung Galaxy J3 9
Samsung Galaxy J7 9
Redmi Redmi 9C NFC 11
Samsung Galaxy A13 14
- TREKKER-M1 Core 6.0.1

What's the log of MMKV when that happened?

From firebase:

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Invalid argument(s): Failed to load dynamic library 'libmmkv.so': dlopen failed: library "libmmkv.so" not found
#00 pc 0x9d9c4b com.viamichelin.android.viamichelinmobile (_open [ffi_dynamic_library_patch.dart:11]) (BuildId: e895227a10d723657e721d91aa4cf28d)
#01 pc 0x6c73bf com.viamichelin.android.viamichelinmobile (MMKVPlatformAndroid._nativeLib [ffi_dynamic_library_patch.dart:22]) (BuildId: e895227a10d723657e721d91aa4cf28d)
#02 pc 0x6c7287 com.viamichelin.android.viamichelinmobile (MMKVPlatformAndroid._mmkvInitialize [mmkv_android.dart:42]) (BuildId: e895227a10d723657e721d91aa4cf28d)
#03 pc 0xa34d6f com.viamichelin.android.viamichelinmobile (MMKVPlatformAndroid.initialize [mmkv_android.dart:62]) (BuildId: e895227a10d723657e721d91aa4cf28d)
#04 pc 0xa34c67 com.viamichelin.android.viamichelinmobile (MMKV.initialize [mmkv.dart:163]) (BuildId: e895227a10d723657e721d91aa4cf28d)

Logcat:

Launching lib/main.dart on SM J330FN in debug mode...
You are applying Flutter's app_plugin_loader Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply

You are applying Flutter's main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply


✓  Built build/app/outputs/flutter-apk/app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:60535/y4HA2NfA6UQ=/ws
E/flutter (18058): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libmmkv.so': dlopen failed: library "libmmkv.so" not found
E/flutter (18058): #0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
E/flutter (18058): #1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
E/flutter (18058): #2      MMKVPlatformAndroid._openDynamicLibrary (package:mmkv_android/mmkv_android.dart:56:37)
E/flutter (18058): #3      MMKVPlatformAndroid.initialize (package:mmkv_android/mmkv_android.dart:75:11)
E/flutter (18058): <asynchronous suspension>
E/flutter (18058): #4      MMKV.initialize (package:mmkv/mmkv.dart:163:12)
E/flutter (18058): <asynchronous suspension>
E/flutter (18058): #5      main (package:mmkv_example/main.dart:40:19)
E/flutter (18058): <asynchronous suspension>
E/flutter (18058):
@T-moz
Copy link
Author

T-moz commented Jun 3, 2024

I tried to implement this solution. But it didn't worked.
#1034 (comment)

@lingol
Copy link
Collaborator

lingol commented Jun 3, 2024

Have you tried running the Android native app demo of mmkv which uses a third party library loader, does it work?

https://github.com/Tencent/MMKV/blob/master/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MyApplication.java#L23

@lingol
Copy link
Collaborator

lingol commented Jun 4, 2024

I don't have access to the devices you listed above so I'm relying on you to test it.
If the Android native demo runs successfully, you can then make a MethodChannel on the Java side of your project to load libmmkv.so by ReLinker, await for that call, then call MMKV.initialize().

void main() async {

  if (Platform.isAndroid) {
    await loadLibrayByReLinker('libmmkv.so');
  }
  // must wait for MMKV to finish initialization
  final rootDir = await MMKV.initialize();
  print('MMKV for flutter with rootDir = $rootDir');

  runApp(MyApp());
}

@T-moz
Copy link
Author

T-moz commented Jun 4, 2024

Have you tried running the Android native app demo of mmkv which uses a third party library loader, does it work?

https://github.com/Tencent/MMKV/blob/master/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MyApplication.java#L23

Thanks for your reply.

The Android native app demo of mmkv also crash on Samsung Galaxy J3:

Logs:

2024-06-04 13:18:33.861  3071-3071  SDAgentPac...teReceiver system_server                        E  Not going to handle 'com.tencent.mmkvdemo'!
2024-06-04 13:18:34.773  3071-3156  system_server           system_server                        E  Failed to open APK '/data/app/com.tencent.mmkvdemo-AmRJqrFspyRz7AfzvYoSYQ==/base.apk' I/O error
2024-06-04 13:18:34.773  3071-3156  ResourcesManager        system_server                        E  failed to add asset path /data/app/com.tencent.mmkvdemo-AmRJqrFspyRz7AfzvYoSYQ==/base.apk
2024-06-04 13:18:35.494  3071-3071  SDAgentPac...teReceiver system_server                        E  Not going to handle 'com.tencent.mmkvdemo'!
2024-06-04 13:18:36.666  2205-2205  encent.mmkvdem          com.tencent.mmkvdemo                 W  Accessing hidden field Landroid/os/Trace;->TRACE_TAG_APP:J (light greylist, reflection)
2024-06-04 13:18:36.667  2205-2205  encent.mmkvdem          com.tencent.mmkvdemo                 W  Accessing hidden method Landroid/os/Trace;->isTagEnabled(J)Z (light greylist, reflection)
2024-06-04 13:18:36.740  2205-2205  MMKV                    com.tencent.mmkvdemo                 I  Enable checkProcessMode()
2024-06-04 13:18:36.998  2205-2205  AndroidRuntime          com.tencent.mmkvdemo                 D  Shutting down VM
2024-06-04 13:18:37.005  2205-2205  AndroidRuntime          com.tencent.mmkvdemo                 E  FATAL EXCEPTION: main
                                                                                                    Process: com.tencent.mmkvdemo, PID: 2205
                                                                                                    java.lang.RuntimeException: Unable to create application com.tencent.mmkvdemo.MyApplication: com.getkeepsafe.relinker.MissingLibraryException: Could not find 'libmmkv.so'. Looked for: [armeabi-v7a, armeabi], but only found: [].
                                                                                                    	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6349)
                                                                                                    	at android.app.ActivityThread.access$1300(ActivityThread.java:242)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loop(Looper.java:216)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:7211)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
                                                                                                    Caused by: com.getkeepsafe.relinker.MissingLibraryException: Could not find 'libmmkv.so'. Looked for: [armeabi-v7a, armeabi], but only found: [].
                                                                                                    	at com.getkeepsafe.relinker.ApkLibraryInstaller.installLibrary(ApkLibraryInstaller.java:173)
                                                                                                    	at com.getkeepsafe.relinker.ReLinkerInstance.loadLibraryInternal(ReLinkerInstance.java:180)
                                                                                                    	at com.getkeepsafe.relinker.ReLinkerInstance.loadLibrary(ReLinkerInstance.java:136)
                                                                                                    	at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:70)
                                                                                                    	at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:51)
                                                                                                    	at com.tencent.mmkvdemo.MyApplication$1.loadLibrary(MyApplication.java:23)
                                                                                                    	at com.tencent.mmkv.MMKV.doInitialize(MMKV.java:221)
                                                                                                    	at com.tencent.mmkv.MMKV.initialize(MMKV.java:208)
                                                                                                    	at com.tencent.mmkvdemo.MyApplication.onCreate(MyApplication.java:20)
                                                                                                    	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1158)
                                                                                                    	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6344)
                                                                                                    	at android.app.ActivityThread.access$1300(ActivityThread.java:242) 
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                                    	at android.os.Looper.loop(Looper.java:216) 
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:7211) 
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975) 
2024-06-04 13:18:37.316  2205-2215  System                  com.tencent.mmkvdemo                 W  A resource failed to call close. 

@lingol
Copy link
Collaborator

lingol commented Jun 4, 2024

Caused by: com.getkeepsafe.relinker.MissingLibraryException: Could not find 'libmmkv.so'. Looked for: [armeabi-v7a, armeabi], but only found: [].

From v1.3.5, MMKV no longer provides armv7 binary. You have two options.

  1. Support armv8 arch as well.
  2. Or build one armv7 binary yourself.

@yuqiaodan
Copy link

yuqiaodan commented Jun 12, 2024

MMKV 1.3.5 Drop armv7 & x86 support. Use version 1.3.4 to resolve this issue
img_v3_02bp_bf9bd184-69f6-4241-88b5-d9a4e0d684fg

@jzlhll

This comment has been minimized.

@lingol lingol closed this as completed Jun 24, 2024
@lingol
Copy link
Collaborator

lingol commented Jul 8, 2024

v1.3.7 LTS has just been release.

This Long Term Support (LTS) release primarily reintroduces support for the ARMv7 architecture and lowers the minimum SDK version requirement to 21. Please note that only critical bug fixes will be applied to the 1.3.x series.

New features will be introduced in version 2.0 and later, which will discontinue support for 32-bit architectures and raise the minimum SDK version requirement to 23.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants