Realm-js: UnsatisfiedLinkError when trying to load RealmReactModule

Created on 4 Aug 2017  路  32Comments  路  Source: realm/realm-js

Hello There

We have an Android app that uses both the Android Realm SDK and the React Native Realm SDK.

Our app is in production and there are around 10 crashes ( <0.1% of users) that is related to java.lang.UnsatisfiedLinkError

Stacktrace

`Caused by java.lang.UnsatisfiedLinkError

java.lang.Runtime.load聽(Runtime.java:332)
java.lang.System.load聽(System.java:1069)
com.facebook.soloader.DirectorySoSource.loadLibraryFrom聽(DirectorySoSource.java:71)
com.facebook.soloader.DirectorySoSource.loadLibrary聽(DirectorySoSource.java:42)
com.facebook.soloader.SoLoader.loadLibraryBySoName聽(SoLoader.java:299)
com.facebook.soloader.SoLoader.loadLibrary聽(SoLoader.java:247)
io.realm.react.RealmReactModule.聽(RealmReactModule.java)
io.realm.react.RealmReactPackage.createNativeModules聽(RealmReactPackage.java:15)

com.facebook.react.NativeModuleRegistryBuilder.processPackage聽(NativeModuleRegistryBuilder.java:107)
聽com.facebook.react.ReactInstanceManager.processPackage聽(ReactInstanceManager.java:1021)
com.facebook.react.ReactInstanceManager.createReactContext聽(ReactInstanceManager.java:959)
com.facebook.react.ReactInstanceManager.access$600聽(ReactInstanceManager.java:108)
com.facebook.react.ReactInstanceManager$ReactContextInitAsyncTask.doInBackground聽(ReactInstanceManager.java:225)

com.facebook.react.ReactInstanceManager$ReactContextInitAsyncTask.doInBackground聽(ReactInstanceManager.java:203)
android.os.AsyncTask$2.call聽(AsyncTask.java:295)
java.util.concurrent.FutureTask.run聽(FutureTask.java:237)
java.util.concurrent.ThreadPoolExecutor.runWorker聽(ThreadPoolExecutor.java:1113)
java.util.concurrent.ThreadPoolExecutor$Worker.run聽(ThreadPoolExecutor.java:588)
java.lang.Thread.run聽(Thread.java:818)`

Android Realm Plugin : 'io.realm:realm-gradle-plugin:3.3.2'
React Realm Dependencies : "realm": "^1.8.3"

it seems like Facebook's DirectorySoSource.java file is trying to load in the RealmModule, but an UnsatisfiedLinkError has occurred. What are some possible reasons of why such an error would be thrown??

O-Community Reproduction-Required T-Help faq

Most helpful comment

For those who wonder, I had the same issue (RN 0.58.6, Realm 2.25.0) and solved it with

defaultConfig{
        ndk {
            // Tells Gradle to build outputs for the following ABIs and package
            // them into your APK.
            abiFilters 'x86', 'armeabi-v7a'//, 'x86_64', 'armeabi'
        }
}

And also:

  • def versionCodes = ["armeabi-v7a": 1, "x86": 2/*, "arm64-v8a": 3*/]
  • include "armeabi-v7a", "x86"//, "arm64-v8a" // uncommented coz realm does not support 64 bit yet

Edit: use this only if you're not planning on releasing a 64 bits version of your app

All 32 comments

Details of exception message:

Caused by java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "" referenced by "/data/app/com.aadhk.woinvoice-1/lib/arm/librealmreact.so"...

@noobiehacker Do you only see the crashes on 64 bit devices? If so, excluding 64 bit (and thereby force loading 32 bit .so files) might be a workaround.

@noobiehacker Did you solve the issue by excluding 64 bit?

@noobiehacker I am closing the issue. If the issue wan't solved by excluding 64 bit, please reopen the issue.

I am getting same stacktrace, bu with java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN5realm4util11uuid_stringEv" /lib/x86/librealmreact.so at the end.
I added abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'

.

@tomas-paronai I suggest that you remove x86_64 and arm64-v8a since RN only supports 32 bit architectures.

@kneth how do you go about doing that? We're getting this issue but we're only including "armeabi-v7a", "x86" in our abiFilters

This seems to only be occuring in 2.11.0. Downgrading to 2.2.8 resolved the issue

I have the same issue on 2.11.0

@abury @behiunforgiven Which symbol cannot be located?

@kneth The same one as @tomas-paronai listed:
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN5realm4util11uuid_stringEv" /lib/x86/librealmreact.so

馃憤

@abury Can you try to upgrade to 2.12.0?

We are currently using https://github.com/facebook/SoLoader to load the .so file but maybe we should switch to https://github.com/KeepSafe/ReLinker. At Realm, we have good experiences with ReLinker (used by Realm Java).

The path (/lib/x86) does look a bit odd. I mean, how can an app install a .so file in a system folder?

@kneth crashes on 2.12.0 and 2.13.0.

java.lang.UnsatisfiedLinkError: couldn't find DSO to load: librealmreact.so

Edit: as @abury said, downgrading to 2.2.8 resolved the issue.

I am not able to reproduce it on my little test app (using Realm JS 2.14.2 and RN 0.55.4) running on my OnePlus One (32 bit ARM device).

@abury @tje3d Can you provide an simple app which reproduces the issue?

@kneth I haven't experienced the issue with the latest version of RN and Realm, so it's all good on my end.

@abury Happy to hear that.

@tje3d Can you try to upgrade?

@kneth thanks, i'l upgrade tomorrow

Still same

realm: 2.14.2
react-native: 0.56.0

More info:

com.android.tools.build: gradle:2.3.3
buildToolsVersion = 27.0.3
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 27
supportLibVersion = 26.1.0
enableProguardInReleaseBuilds = true
08-16 15:55:50.271 17794 17813 E SoLoader: Could not load: librealmreact.so
--------- beginning of crash
08-16 15:55:50.272 17794 17813 E AndroidRuntime: FATAL EXCEPTION: Thread-2
08-16 15:55:50.272 17794 17813 E AndroidRuntime: Process: com.test, PID: 17794
08-16 15:55:50.272 17794 17813 E AndroidRuntime: java.lang.UnsatisfiedLinkError: couldn't find DSO to load: librealmreact.so
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:522)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:420)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:370)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:335)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at io.realm.react.RealmReactModule.<clinit>(RealmReactModule.java:59)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at io.realm.react.RealmReactPackage.createNativeModules(RealmReactPackage.java:31)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:109)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1175)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1145)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1086)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:116)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:916)
08-16 15:55:50.272 17794 17813 E AndroidRuntime:    at java.lang.Thread.run(Thread.java:764)
08-16 15:55:50.273  1476  6456 W ActivityManager:   Force finishing activity com.test/.MainActivity
08-16 15:55:50.274  1476  6456 D ActivityTrigger: ActivityTrigger activityPauseTrigger 

@tje3d I notice enableProguardInReleaseBuilds = true and think of #1960. Could you try to unzip your apk file and see what .so files it contains?

I solve the issue with, using the latest realm 2.22.0
enableProguardInReleaseBuilds = false

The same crash occurred to my app after rebuilding it from scratch with React Native 0.58. Comparing the android/app/build.gradle with my old repo, I noticed that the abiFilters was not present anymore. Thanks @tomas-paronai for you comment.

I was able to reproduce it.

Steps to reproduce this:

  • $ react-native init RNTestApp
  • $ cd RNTestApp
  • $ yarn add realm
  • $ react-native link
  • run via Android Studio

Crash Log

E/SoLoader: Error when loading lib: dlopen failed: "/data/data/com.rntestapp/lib-main/librealmreact.so" is 32-bit instead of 64-bit lib hash:  47698cc5a6c9aa1799fbd19efe73cb1 search path is /data/app/com.rntestapp-8JMLgQo3CER0yhlhw8s-Ww==/lib/arm64
    couldn't find DSO to load: librealmreact.so caused by: dlopen failed: "/data/data/com.rntestapp/lib-main/librealmreact.so" is 32-bit instead of 64-bit
E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: com.rntestapp, PID: 13166
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: librealmreact.so caused by: dlopen failed: "/data/data/com.rntestapp/lib-main/librealmreact.so" is 32-bit instead of 64-bit
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
        at io.realm.react.RealmReactModule.<clinit>(RealmReactModule.java:56)
        at io.realm.react.RealmReactPackage.createNativeModules(RealmReactPackage.java:31)
        at com.facebook.react.ReactPackageHelper.getNativeModuleIterator(ReactPackageHelper.java:42)
        at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:40)
        at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1212)
        at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1182)
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1120)
        at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:123)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:943)
        at java.lang.Thread.run(Thread.java:780)

@martnst Yes, the explanation is dlopen failed: "/data/data/com.rntestapp/lib-main/librealmreact.so" is 32-bit instead of 64-bit lib and the fix is using abiFilters. For 64 bit support, see #2221.

Still got the error on latest version React Native (0.59.1), Realm 2.25.0. A crash app on some Android devices.

@MichaelHuy Do you by any chance mix 32 bit and 64 bit? Realm is currently only 32 bit.

@kneth Thanks for your feedback. How can I mix 32 bit and 64 bit? I remembered I removing all 64 configurations ("arm64-v8a", "x86_64") but still got the error?

@MichaelHuy I am asking since you are using RN 0.59 which supports 64 bit. Please post the stack trace if possible.

@kneth java.lang.UnsatisfiedLinkError: couldn't find DSO to load: librealmreact.so caused by: dlopen failed: "/data/data/com.nox.identiv/lib-main/librealmreact.so" is 32-bit instead of 64-bit at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:738) at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:591) at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:529) at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484) at io.realm.react.RealmReactModule.<clinit>(RealmReactModule.java:56) at io.realm.react.RealmReactPackage.createNativeModules(RealmReactPackage.java:31) at com.facebook.react.ReactPackageHelper.getNativeModuleIterator(ReactPackageHelper.java:42) at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:40) at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1212) at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1182) at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1120) at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:123) at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:943) at java.lang.Thread.run(Thread.java:818)

@MichaelHuy Your issue is similar to https://github.com/facebook/SoLoader/issues/29 - but that's not helping you.

I suggest that you unzip the apk file and examine all the .so files. If just one is 64 bit, it can explain why you see the error.

For those who wonder, I had the same issue (RN 0.58.6, Realm 2.25.0) and solved it with

defaultConfig{
        ndk {
            // Tells Gradle to build outputs for the following ABIs and package
            // them into your APK.
            abiFilters 'x86', 'armeabi-v7a'//, 'x86_64', 'armeabi'
        }
}

And also:

  • def versionCodes = ["armeabi-v7a": 1, "x86": 2/*, "arm64-v8a": 3*/]
  • include "armeabi-v7a", "x86"//, "arm64-v8a" // uncommented coz realm does not support 64 bit yet

Edit: use this only if you're not planning on releasing a 64 bits version of your app

@AlexandreRozier Many places 馃. Thanks for the update.

@AlexandreRozier your solution that implies that side effects could exist?

@brayanL The solution above requires that all your libraries come in 32 bit versions. And that you only use the 32 bit versions (even if a 64 bit version exists).

Was this page helpful?
0 / 5 - 0 ratings