Realm-js: App crashing with proguard enabled in react-native 0.57.X - couldn't find DSO to load: librealmreact.so

Created on 15 Aug 2018  路  29Comments  路  Source: realm/realm-js

Goals

Trying to build a production ready apk (Android).

Actual Results

App crashes if proguard is enabled (def enableProguardInReleaseBuilds = true).

    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: librealmreact.so
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:522)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:420)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:370)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:335)
        at io.realm.react.RealmReactModule.<clinit>(RealmReactModule.java:59)

It crashes no matter if you split in several apks or only one.

This is my proguard config:

# Disabling obfuscation is useful if you collect stack traces from production crashes
# (unless you are using a system that supports de-obfuscate the stack traces).
-dontobfuscate

# React Native

# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip

# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.proguard.annotations.DoNotStrip class *
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
    @com.facebook.proguard.annotations.DoNotStrip *;
    @com.facebook.common.internal.DoNotStrip *;
}

-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
  void set*(***);
  *** get*();
}

-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
-keepclassmembers class *  { @com.facebook.react.uimanager.UIProp <fields>; }
-keepclassmembers class *  { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
-keepclassmembers class *  { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }

-dontwarn com.facebook.react.**

# okhttp

-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

# okio

-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

Version of Realm and Tooling

  • Realm JS SDK Version: 2.12.0
  • React Native: 0.56.0
  • Client OS & Version: OSX High Sierra
O-Community T-Enhancement

Most helpful comment

Hi, I add "-keep class io.realm.react.**" into the file proguard-rules.pro. Now it runs well

All 29 comments

Please try to unzip your apk and see what .so it contains.

I have tried to enable Proguard on a small app, and the .so is added correctly.

in soLoader lib changed api method signature loadLibrary():bool instead of expected loadLibrary():void... soLoader highest compatible lib version is 0.4.+

Solution is downgrade the Fresco and soLoader libs versions. 10.9.+ and 0.4.+

@OleksandrKucherenko Thanks for the suggestions.

@OleksandrKucherenko hello. I have these versions

compile 'com.facebook.fresco:fresco:1.9.0'
compile 'com.facebook.soloader:soloader:0.3.0'

android/app/build.gradle

android {
...
  defaultConfig {
  ...
     ndk {
        abiFilters "armeabi-v7a", "x86"
     }
  ...
  }
  splits {
    abi {  
       ...
       include "armeabi-v7a", "x86"
       ...
     }
  }
...
}

apk contains 2 files librealmreact.so in lib/armeabi-v7a and lib/x86

but it doesn't help to solve issue

09-17 10:10:09.619 10283 10304 E AndroidRuntime: java.lang.UnsatisfiedLinkError: couldn't find DSO to load: librealmreact.so
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:522)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:420)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:370)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:335)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at io.realm.react.RealmReactModule.<clinit>(RealmReactModule.java:59)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at io.realm.react.RealmReactPackage.createNativeModules(RealmReactPackage.java:31)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:109)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1175)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1145)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1086)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:116)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:916)
09-17 10:10:09.619 10283 10304 E AndroidRuntime:    at java.lang.Thread.run(Thread.java:760)

2 @serjiogunit : it sounds like librealmreact.so library is not a part of the final android binary.

Just use Android Studio feature ' analyze APK..." and check that inside the final binary librealmreact.so file exists. Also, analyze how proguard rename the classes, are they included into first DEX file or into second/third one.

next step is to validate which ABI used on the device... x64 vs x86, etc.

next step is to try to follow - https://github.com/facebook/fresco/issues/2049#issuecomment-375257032

I still have same issue with "react-native": "^0.57.7" and "realm": "^2.21.0",. @kneth I unzipped the .apk, it seems the librealmreact.so is there:

lib/armeabi-v7a/librealmreact.so

(there is only armeabi-v7ain lib folder)

But the error says:

2018-12-21 18:15:25.050 7434-7449/? E/SoLoader: couldn't find DSO to load: librealmreact.so caused by: Error: Cannot load /data/app/com.my.package-0uWDsr7mBpTMJ4J4ENo9cw==/lib/arm/librealmreact.so

Can be wrong path somehow? Any ideas?

Also experiencing the same issue with Realm 2.21.1 and React Native 0.57.8 when compiling with proguard.

I wonder if somebody tried this with R8 (that should deprecate proguard) ?

New code shrinker

R8 is a new tool for code shrinking and obfuscation that replaces ProGuard. You can start using the preview version of R8 by including the following in your project鈥檚 gradle.properties file:

android.enableR8 = true

See https://developer.android.com/studio/releases/?utm_source=android-studio&utm_medium=studio-assistant#R8

I'll have a lookie, see if anything changes.
Just annoying really.
Having to keep Realm at 2.2.20 as anything i have tried so far above that version gives this exact issue.

@ferrannp It says /lib/arm/librealmreact.so instead of arm-v7a. What Android device are you trying to run APK on?

Another suggestion might be that it could be related to App Bundles if you are shipping your app using that? Realm Java had a bug that could look similar to what you are seeing: https://github.com/realm/realm-java/issues/5977

Pretty much got the app to split with these filters -> "armeabi-v7a", "x86"
Not currently using the new App Bundles feature.
Also running tests on a Samsung Galaxy s7 Edge and Galaxy s5.

Yes I got the two splits two:

app-armeabi-v7a-release.apk
app-x86-release.apk

Without proguard is fine. It does not matter if you split or not, the resulted .apk crashes.

Would be nice to see a fix for this as we can't upgrade without disabling proguard.
@kneth Any resolution?

It might be a good time to switch to ReLinker.

@ferrannp Same issue here. Any solutions?
What I wondered is why android load librealmreact.so from "xxx/lib/arm/" but not "xxx/lib/armeabi-v7a"?

Hi, I add "-keep class io.realm.react.**" into the file proguard-rules.pro. Now it runs well

Sadly that doesn't help :/
Have had that in my proguard rules file for a long while.

@8BallBomBom
Below is my version of realm and tools
Realm: 2.22.0
React Native: 0.57.2
React: 16.5.1
And build environment:
compileSdkVersion = 27
buildToolsVersion = "27.0.3"
minSdkVersion = 19
targetSdkVersion = 26
supportLibVersion = "27.1.1"
Hope this will be helpful

Very close to what i'm running.
Thanks, will have a mess :)

So I updated realm to 2.22.0 and the error seems to be gone. This is what I have now:

"react-native": "0.57.8",
"realm": "^2.22.0",

And I only had to add one line to my proguard-rules.pro:

-keep class io.realm.react.util.SSLHelper

@adyanced your .apk will be smaller just with that line instead of the whole realm.react.

@kneth did anything change that this is fixed? Anyway we can avoid extra line in proguard file? (or should be documented or added to the realm proguard itself?).

@ferrannp I think #2177 might have helped.

@cmelchior Do you know if we can get rid of that proguard line?

Any update on this?
I can't build my application :disappointed:

Any update on this ?
Getting the following error and app is crashing immediately after opening. Happening only for arm64-v8a apk

java.lang.UnsatisfiedLinkError: couldn't find DSO to load: librealmreact.so
at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:703)
at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:564)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:500)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:455)
at io.realm.react.RealmReactModule.(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:764)

@reachtokish We currently don't support 64 bit. You need to include 32 bit only. See for example https://github.com/realm/realm-js/issues/2221#issuecomment-482131628

react-native : "0.59.3"
Adding :
ndk { abiFilters "armeabi-v7a", "x86" }
To build.gradle defaultConfig fixed it for me.

I will close this issue because it is creating confusion. Realm works with proguard (see comments), what it does not work is 64bits yet.

Sorry i didn't get back but yes the issue i had was resolved by upgrading React Native and running clean builds.

So I updated realm to 2.22.0 and the error seems to be gone. This is what I have now:

"react-native": "0.57.8",
"realm": "^2.22.0",

And I only had to add one line to my proguard-rules.pro:

-keep class io.realm.react.util.SSLHelper

@adyanced your .apk will be smaller just with that line instead of the whole realm.react.

@kneth did anything change that this is fixed? Anyway we can avoid extra line in proguard file? (or should be documented or added to the realm proguard itself?).

If onlyenableProguardInReleaseBuilds = true, then this setting is effective, it solved my problem
-keep class io.realm.react.util.SSLHelper

Was this page helpful?
0 / 5 - 0 ratings