react-native-mmkv
react-native-mmkv copied to clipboard
Android crash library "libreactnativemmkv.so" not found
Description
I have a simple project which is working. After I add react-native-mmkv this problem arises. Android build completes successfully, but in bundle time I get this error:
Error: Exception in HostFunction: java.lang.UnsatisfiedLinkError: dlopen failed: library "libreactnativemmkv.so" not found
It works perfectly in iOS though.
Useful information:
OS: MacOS 12.0.1 React Native: 0.65.1 React Native MMKV: 2.4.1 Reanimated: 2.8.0 Hermes is enabled
Can you try cleaning Gradle cache and rebuilding the project?
Yes sure. I did try that and no luck. I get this error on Android emulator and device:
Error: Exception in HostFunction: java.lang.UnsatisfiedLinkError: dlopen failed: library "libreactnativemmkv.so" not found
I just wanted to note both the emulator and the device are running on Android 11.
Can you run the example/ app here?
This bug is really weird, maybe try upgrading to RN 0.66?
Tried both of your suggestions @mrousavy. Upgrading to RN 0.66 doesn't help. I created a brand new project with this command:
npx react-native init NewProject --version 0.66
Then I added MMKV to the project with
yarn add react-native-mmkv
And it keeps throwing me the same error message when I want to run the project.
Your example has the same issue. It builds successfully, but in bundling gives me the same error message in metro.
ERROR Error: Exception in HostFunction: java.lang.UnsatisfiedLinkError: dlopen failed: library "libreactnativemmkv.so" not found, js engine: hermes
ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
I'm confused why it happens, because it only happens when I add this lib to the project. It might be helpful to say this is not happening on Windows, just on Mac OS.
same issue on Android, on iOS is fine
Upgraded react native to 0.69.2 and this issue still exists.
It seems that 2.4.2
caused the issue, reverting to 2.4.1 fixed it for now
Closing since it is fixed in new releases.
@SMhdAsadi in which version it is fixed? because I am using mmkv 2.5.1
and on RN 0.70.13
and I am still facing this issue
and I cannot upgrade to mmkv to 2.6.+
as my project is brownfield setup, and upgrading it to 0.71 will require time
Fatal Exception: zc.c: Error: Exception in HostFunction: java.lang.UnsatisfiedLinkError: dlopen failed: library "libreactnativemmkv.so" not found, js engine: hermes, stack:
value@57:1671
anonymous@51:1596
anonymous@642:1340
t@641:612
anonymous@627:291
h@2:1707
d@2:1150
i@2:496
anonymous@587:701
h@2:1707
d@2:1150
i@2:496
anonymous@437:151
h@2:1707
d@2:1150
i@2:496
anonymous@436:873
h@2:1707
d@2:1150
i@2:496
anonymous@384:667
h@2:1707
d@2:1150
i@2:496
anonymous@6:70
h@2:1707
d@2:1080
i@2:496
global@2712:3
at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:72)
at java.lang.reflect.Method.invoke(Method.java)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
at com.facebook.jni.NativeRunnable.run(NativeRunnable.java)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:257)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
at java.lang.Thread.run(Thread.java:923)
@sanjeevyadavIT Sorry I can't remember the exact version. I'm using version 2.8.0 right now.
@SMhdAsadi I have used react native mmkv version "2.10.2" and I am still getting same error, did I get fix for you for 2.8.0
@sanjeevyadavIT did you manage to fix it?
It seems like "libreactnativemmkv.so" library is not found, which can happen when "MMKV" library is not linked correctly.
- Check if MMKV library is linked.
native link @react-native-mmkv
or link mannually
- Add following codes to the path "android/settings.gradle"
include ':react-native-mmkv'
project(':react-native-mmkv').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mmkv/android')
- Add following codes to the path "android/app/build.gradle"
dependencies {
...
implementation project(':react-native-mmkv')
}
- Check if Hermes engine activity
- Add following codes to the path "android/app/build.gradle"
project.ext.react = [
enableHermes: true // clean and rebuild if changing
]