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

SoLoader causes instrumented tests to crash #94

Closed
CiaraSouthgateTR opened this issue Mar 18, 2022 · 15 comments
Closed

SoLoader causes instrumented tests to crash #94

CiaraSouthgateTR opened this issue Mar 18, 2022 · 15 comments

Comments

@CiaraSouthgateTR
Copy link

Bug Report

SoLoader looks for libfbjni in the .test path during instrumented tests. I am not sure how it makes that decision, since package name still reports without .test.
Since the tests use a debug variant, I don't see a way to prevent Flipper loading during instrumented tests.

java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/app/com.appscoop.takingroot.staging.test-1Dt01Y4N51I9qkS3sSAU3w==/base.apk!/lib/x86/libfbjni.so" not found
  at java.lang.Runtime.load0(Runtime.java:938)
  at java.lang.System.load(System.java:1631)
  at com.facebook.soloader.SoLoader$1.load(SoLoader.java:529)
  at com.facebook.soloader.DirectApkSoSource.loadLibrary(DirectApkSoSource.java:77)
  at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:1038)
  at com.facebook.soloader.SoLoader.loadLibraryBySoNameImpl(SoLoader.java:914)
  at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:826)
  at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:773)
  at com.facebook.soloader.NativeLoaderToSoLoaderDelegate.loadLibrary(NativeLoaderToSoLoaderDelegate.java:29)
  at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(NativeLoader.java:51)
  at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(NativeLoader.java:30)
  at com.facebook.jni.HybridData.<clinit>(HybridData.java:34)
  at com.facebook.flipper.android.FlipperThread.run(FlipperThread.java:25)
libfbjni.so not found on /vendor/lib
libfbjni.so not found on /system/lib
couldn't find DSO to load: libfbjni.so
 SoSource 0: com.facebook.soloader.DirectorySoSource[root = /data/app/com.appscoop.takingroot.staging-_zWOlH2oMX4dVzDGOq6zXw==/lib/x86 flags = 0]
 SoSource 1: com.facebook.soloader.DirectApkSoSource[root = /data/app/com.appscoop.takingroot.staging.test-1Dt01Y4N51I9qkS3sSAU3w==/base.apk!/lib/x86]
 SoSource 2: com.facebook.soloader.DirectorySoSource[root = /vendor/lib flags = 2]
 SoSource 3: com.facebook.soloader.DirectorySoSource[root = /system/lib flags = 2]
 Native lib dir: /data/app/com.appscoop.takingroot.staging-_zWOlH2oMX4dVzDGOq6zXw==/lib/x86
 result: 0
FATAL EXCEPTION: FlipperEventBaseThread
Process: com.appscoop.takingroot.staging, PID: 5862
java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libfbjni.so
    SoSource 0: com.facebook.soloader.DirectorySoSource[root = /data/app/com.appscoop.takingroot.staging-_zWOlH2oMX4dVzDGOq6zXw==/lib/x86 flags = 0]
    SoSource 1: com.facebook.soloader.DirectApkSoSource[root = /data/app/com.appscoop.takingroot.staging.test-1Dt01Y4N51I9qkS3sSAU3w==/base.apk!/lib/x86]
    SoSource 2: com.facebook.soloader.DirectorySoSource[root = /vendor/lib flags = 2]
    SoSource 3: com.facebook.soloader.DirectorySoSource[root = /system/lib flags = 2]
    Native lib dir: /data/app/com.appscoop.takingroot.staging-_zWOlH2oMX4dVzDGOq6zXw==/lib/x86
result: 0
    at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:1098)
    at com.facebook.soloader.SoLoader.loadLibraryBySoNameImpl(SoLoader.java:914)
    at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:826)
    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:773)
    at com.facebook.soloader.NativeLoaderToSoLoaderDelegate.loadLibrary(NativeLoaderToSoLoaderDelegate.java:29)
    at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(NativeLoader.java:51)
    at com.facebook.soloader.nativeloader.NativeLoader.loadLibrary(NativeLoader.java:30)
    at com.facebook.jni.HybridData.<clinit>(HybridData.java:34)
    at com.facebook.flipper.android.FlipperThread.run(FlipperThread.java:25)
FATAL EXCEPTION: FlipperConnectionThread
Process: com.appscoop.takingroot.staging, PID: 5862
 java.lang.NoClassDefFoundError: <clinit> failed for class com.facebook.flipper.android.EventBase; see exception in other thread
    at com.facebook.flipper.android.FlipperThread.run(FlipperThread.java:25)

To Reproduce

Run an instrumented test

Environment

Android API 31
debugImplementation 'com.facebook.flipper:flipper:0.137.0'
debugImplementation 'com.facebook.soloader:soloader:0.10.3'
releaseImplementation 'com.facebook.flipper:flipper-noop:0.137.0'

@henryzx
Copy link

henryzx commented Mar 23, 2022

same here. any update?

@CiaraSouthgateTR
Copy link
Author

@RowlandOti
Copy link

RowlandOti commented Apr 7, 2022

Co-experiencing this issue. @CiaraSouthgateFT are you able to clarify how that solution you posted helps?

@twyatt
Copy link

twyatt commented May 12, 2022

@RowlandOti I believe what @CiaraSouthgateFT was saying is that they conditionally don't use SoLoader if they're within an instrumentation test.

For example, if you create a file under your test or androidTest source set:

package com.example

object TestMarker

Then you can detect if you're running in a test (in your main or debug source set):

private val isTest: Boolean
    get() = try {
        Class.forName("com.example.TestMarker")
        true
    } catch (e: ClassNotFoundException) {
        false
    }

Then, where you normally use SoLoader:

if (!isTest) SoLoader.init(context, false)

...it doesn't "fix" the issue, but does allow instrumentation tests to run (where SoLoader and tools like Flipper, are not needed).

Hope that helps.

@ericschaal
Copy link

ericschaal commented May 13, 2022

Hi,

I encountered the same issue while running Detox (instrumented tests) on a React Native 0.68 project with Hermes enabled. AndroidJUnitRunner would instantly crash at startup.

...
crashes with java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so

I was able to solve it by downgrading SoLoader to v0.9.0+ using resolutionStrategy.

Any idea why this is happening?

EDIT:
I also tried various 0.10.x versions
v0.10.1 is working
v0.10.2 is crashing
v0.10.3 is crashing

Looks like something broke in v0.10.2

@netshade
Copy link

I also ran into the same problem as @ericschaal and your research helped me get our Android Detox tests running again. Thanks very much.

@mikehardy
Copy link

In turn, I was mentioned in that linked wix/Detox issue and was curious what was going on here. It appears that there has been a mountain of work in this repo since the last release, all directly affecting the code paths in question, so examining the diff between 0.10.1 (working) and 0.10.2 (not working) isn't that fruitful since "current stable" is so different.

Begs the question: is it possible to get a new release from current repo state (even if just attached) and some guidance on how to integrate it via gradle so testing + a reproduction repo is productive?

@mehmetarikan
Copy link

Stumble upon the same issue when updating the flipper to latest(0.149.0) version. After digging it I noticed that flipper updates its soLoader dependency on v0.119.0 from 0.10.1 to 0.10.3. I verified flipper v0.118.1 works without any issue but v0.119.0 crashes all instrumented tests to fail. I disabled flipper for the tests but we also use yogalayout and have to load soLoader and due to this transitive dependency tests were still failing. I fix the problem by enforcing soLoader to v0.10.1.

implementation('com.facebook.soloader:soloader') {
        version {
            strictly '0.10.1'
        }
    }

@tinder-cesardiez
Copy link

Issue seems to be gone for us after updating the SoLoader dependency to 10.0.4:
https://github.com/facebook/SoLoader/releases/tag/v0.10.4

@RowlandOti
Copy link

Yes, I can see a commit that explains why this happens as well as the applied fix: 9008446

@mikehardy
Copy link

mikehardy commented Jul 18, 2022

So it seems soloader 0.10.4 fixes it
It appears Flipper 0.154.0 ingests the fix facebook/flipper@23f7e2b

I'm posting this info for react-native here for release planning purposes reactwg/react-native-releases#26 (comment) (just merged on react-native main, should hopefully be in react-native 0.70.0 when released)

mikehardy added a commit to facebook/react-native that referenced this issue Jul 18, 2022
soloader 0.10.3 will apparently cause crashes in instrumented tests, 0.10.4 appears to fix these crashes

Related: facebook/SoLoader#94
Related: reactwg/react-native-releases#26 (comment)
facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Jul 19, 2022
Summary:
soloader 0.10.3 will apparently cause crashes in instrumented tests, 0.10.4 appears to fix these crashes

Related: facebook/SoLoader#94
Related: reactwg/react-native-releases#26 (comment)

## Changelog

[Android] [Changed] - Bump Soloader to 0.10.4

Pull Request resolved: #34213

Test Plan: This is hard to test since it's in the AAR etc., I'm hoping CI is sufficient as the previous soloader bump PR went through similarly

Reviewed By: cipolleschi

Differential Revision: D37960320

Pulled By: cortinico

fbshipit-source-id: ce1611d7b30df737c8525a70839b5491a6585c75
@Gerlison
Copy link

Gerlison commented Jul 21, 2022

Issue seems to be gone for us after updating the SoLoader dependency to 10.0.4: https://github.com/facebook/SoLoader/releases/tag/v0.10.4

Yes, I can see a commit that explains why this happens as well as the applied fix: 9008446

So it seems soloader 0.10.4 fixes it It appears Flipper 0.154.0 ingests the fix facebook/flipper@23f7e2b

I'm posting this info for react-native here for release planning purposes reactwg/react-native-releases#26 (comment) (just merged on react-native main, should hopefully be in react-native 0.70.0 when released)

All these answers helped me.
Firstly i tried just to use specific version of soloader (0.10.4+)
image
, and that alone didn't work for detox test build, because it was causing another error. Which, later, I solved by doing the following guide:
https://wix.github.io/Detox/docs/introduction/android/#setting-detox-up-as-a-compiling-dependency

Thank you all

kelset pushed a commit to facebook/react-native that referenced this issue Jul 27, 2022
Summary:
soloader 0.10.3 will apparently cause crashes in instrumented tests, 0.10.4 appears to fix these crashes

Related: facebook/SoLoader#94
Related: reactwg/react-native-releases#26 (comment)

## Changelog

[Android] [Changed] - Bump Soloader to 0.10.4

Pull Request resolved: #34213

Test Plan: This is hard to test since it's in the AAR etc., I'm hoping CI is sufficient as the previous soloader bump PR went through similarly

Reviewed By: cipolleschi

Differential Revision: D37960320

Pulled By: cortinico

fbshipit-source-id: ce1611d7b30df737c8525a70839b5491a6585c75
@ko-devHong
Copy link

ko-devHong commented Oct 23, 2022

Upgrading from 63.0 to 0.70.0 resolved the issue with ios, but the problem is not solved at all in Android. It seems to be a soloader problem that many people refer to.

i already added implementation 'com.facebook.soloader:soloader:0.10.4+'

this is my log

752-8752/**** E/SoLoader: couldn't find DSO to load: libjsc.so
    	SoSource 0: com.facebook.soloader.DirectorySoSource[root = /data/app/~~Es-u6o8MM1pCV02wkZHNxQ==/*****-zVphl1YCSx-HLrtHV-X58Q==/lib/arm64 flags = 0]
    	SoSource 1: com.facebook.soloader.DirectApkSoSource[root = (/data/app/~~Es-u6o8MM1pCV02wkZHNxQ==/*****-zVphl1YCSx-HLrtHV-X58Q==/base.apk!/lib/arm64-v8a, )]
    	SoSource 2: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
    	SoSource 3: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
    	Native lib dir: /data/app/~~Es-u6o8MM1pCV02wkZHNxQ==/*****-zVphl1YCSx-HLrtHV-X58Q==/lib/arm64
     result: 0
2022-10-23 19:02:05.123 8752-8752/***** E/SoLoader: couldn't find DSO to load: libjscexecutor.so caused by: couldn't find DSO to load: libjsc.so
    	SoSource 0: com.facebook.soloader.DirectorySoSource[root = /data/app/~~Es-u6o8MM1pCV02wkZHNxQ==/*****-zVphl1YCSx-HLrtHV-X58Q==/lib/arm64 flags = 0]
    	SoSource 1: com.facebook.soloader.DirectApkSoSource[root = (/data/app/~~Es-u6o8MM1pCV02wkZHNxQ==/*******-zVphl1YCSx-HLrtHV-X58Q==/base.apk!/lib/arm64-v8a, )]
    	SoSource 2: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2]
    	SoSource 3: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2]
    	Native lib dir: /data/app/~~Es-u6o8MM1pCV02wkZHNxQ==/*****-zVphl1YCSx-HLrtHV-X58Q==/lib/arm64
     result: 0 result: 0
2022-10-23 19:02:05.124 8752-8752/******* E/SoLoader: couldn't find DSO to load: libhermes.so caused by: dlopen failed: library "/vendor/lib64/libhermes.so" not found result: 0
2022-10-23 19:02:05.124 1233-1233/? E/audit: type=1400 audit(1666519325.120:34327460): avc:  denied  { read } for  pid=8752 comm="gym.app.staging" name="libhermes.so" dev="dm-9" ino=3278 scontext=u:r:untrusted_app:s0:c243,c258,c512,c768 tcontext=u:object_r:vendor_file:s0 tclass=file permissive=0 SEPF_SM-S906N_12_0001 audit_filtered
2022-10-23 19:02:05.125 8752-8752/****** E/AndroidRuntime: FATAL EXCEPTION: main
    Process: *****, PID: 8752
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so caused by: dlopen failed: library "/vendor/lib64/libhermes.so" not found result: 0
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:1127)
        at com.facebook.soloader.SoLoader.loadLibraryBySoNameImpl(SoLoader.java:943)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:855)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:802)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:772)
        at com.facebook.hermes.reactexecutor.HermesExecutor.loadLibrary(HermesExecutor.java:25)
        at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:19)
        at com.facebook.hermes.reactexecutor.HermesExecutor.loadLibrary(HermesExecutor.java:23)
        at com.facebook.react.ReactInstanceManagerBuilder.getDefaultJSExecutorFactory(ReactInstanceManagerBuilder.java:393)
        at com.facebook.react.ReactInstanceManagerBuilder.build(ReactInstanceManagerBuilder.java:343)
        at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:96)
        at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:42)
        at com.soundgym.app.MainApplication.onCreate(MainApplication.java:76)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1211)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7588)
        at android.app.ActivityThread.access$1700(ActivityThread.java:315)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2286)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8751)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
     Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: library "/vendor/lib64/libhermes.so" not found
        at java.lang.Runtime.load0(Runtime.java:929)
        at java.lang.System.load(System.java:1620)
        at com.facebook.soloader.SoLoader$1.load(SoLoader.java:558)
        at com.facebook.soloader.DirectorySoSource.loadLibraryFrom(DirectorySoSource.java:110)
        at com.facebook.soloader.DirectorySoSource.loadLibrary(DirectorySoSource.java:63)

@simpleton
Copy link
Member

Hi @ko-devHong, can you share the crashy apk?

@simpleton
Copy link
Member

This issue should be addressed in 0.10.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests