realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.62k stars 558 forks source link

UnsatisfiedLinkError when trying to load RealmReactModule #1187

Closed DeArchiTech closed 5 years ago

DeArchiTech commented 6 years ago

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??

DeArchiTech commented 6 years ago

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"...

kneth commented 6 years ago

@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.

kneth commented 6 years ago

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

kneth commented 6 years ago

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

parohy commented 6 years ago

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'

.

kneth commented 6 years ago

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

abury commented 5 years ago

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

abury commented 5 years ago

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

behiunforgiven commented 5 years ago

I have the same issue on 2.11.0

kneth commented 5 years ago

@abury @behiunforgiven Which symbol cannot be located?

abury commented 5 years ago

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

👍

kneth commented 5 years ago

@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?

tje3d commented 5 years ago

@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.

kneth commented 5 years ago

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?

abury commented 5 years ago

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

kneth commented 5 years ago

@abury Happy to hear that.

@tje3d Can you try to upgrade?

tje3d commented 5 years ago

@kneth thanks, i'l upgrade tomorrow

tje3d commented 5 years ago

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 
kneth commented 5 years ago

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

ariefwidiatmoko commented 5 years ago

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

martnst commented 5 years ago

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:

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)
kneth commented 5 years ago

@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.

MichaelHuy commented 5 years ago

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

kneth commented 5 years ago

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

MichaelHuy commented 5 years ago

@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?

kneth commented 5 years ago

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

MichaelHuy commented 5 years ago

@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)

kneth commented 5 years ago

@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.

AlexandreRozier commented 5 years ago

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:

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

kneth commented 5 years ago

@AlexandreRozier Many places 🤔. Thanks for the update.

brayanL commented 5 years ago

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

kneth commented 5 years ago

@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).