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

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

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 30 (7 by maintainers)

Most upvoted comments

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

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

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

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

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

@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

It might be a good time to switch to ReLinker.

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’s gradle.properties file:

android.enableR8 = true

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