Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ferrannp opened this issue Aug 15, 2018 · 30 comments

Comments

@ferrannp
Copy link

ferrannp commented Aug 15, 2018

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
@kneth
Copy link
Contributor

kneth commented Aug 16, 2018

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.

@OleksandrKucherenko
Copy link

OleksandrKucherenko commented Aug 21, 2018

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

@kneth
Copy link
Contributor

kneth commented Aug 23, 2018

@OleksandrKucherenko Thanks for the suggestions.

@serjiogunit
Copy link

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

@OleksandrKucherenko
Copy link

OleksandrKucherenko commented Sep 17, 2018

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 - facebook/fresco#2049 (comment)

@ferrannp
Copy link
Author

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?

@ferrannp ferrannp changed the title App crashing with proguard enabled in react-native 0.56.0 - couldn't find DSO to load: librealmreact.so App crashing with proguard enabled in react-native 0.57.X - couldn't find DSO to load: librealmreact.so Dec 21, 2018
@8BallBomBom
Copy link

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

@ferrannp
Copy link
Author

ferrannp commented Jan 4, 2019

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

@8BallBomBom
Copy link

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.

@cmelchior
Copy link
Contributor

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

@cmelchior
Copy link
Contributor

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: realm/realm-java#5977

@8BallBomBom
Copy link

8BallBomBom commented Jan 7, 2019

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.

@ferrannp
Copy link
Author

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.

@8BallBomBom
Copy link

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

@kneth
Copy link
Contributor

kneth commented Jan 14, 2019

It might be a good time to switch to ReLinker.

@adyanced
Copy link

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

@adyanced
Copy link

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

@8BallBomBom
Copy link

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

@adyanced
Copy link

@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

@8BallBomBom
Copy link

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

@ferrannp
Copy link
Author

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

@kneth
Copy link
Contributor

kneth commented Jan 28, 2019

@ferrannp I think #2177 might have helped.

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

@mnlbox
Copy link

mnlbox commented Apr 16, 2019

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

@reachtokish
Copy link

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)

@kneth
Copy link
Contributor

kneth commented Apr 23, 2019

@reachtokish We currently don't support 64 bit. You need to include 32 bit only. See for example #2221 (comment)

@AppMedecine
Copy link

AppMedecine commented Apr 26, 2019

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

@ferrannp
Copy link
Author

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

@8BallBomBom
Copy link

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

@seth-shi
Copy link

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

@saracasticshailz
Copy link

Simplest way to find the issue is, create an apk with debuggable enabled & run it over device while connected to android studio & check logcat, in there you will see which package/lib exactly you need to add in -keep.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests