From 25a2d47a98d907731feaa23faa613fdc647ebc56 Mon Sep 17 00:00:00 2001 From: Sim Sun Date: Thu, 4 Nov 2021 11:11:08 -0700 Subject: [PATCH] Add splitApkSource in the head of soSources Summary: # Context There're several user reported the new version(0.10.2) still crash on some devices. ``` With 0.10.2 it fixed the Google Pixel 6 Pro but mine (S21) started to crash Here's the crash: Fatal Exception: java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libjscexecutor.so SoSource 0: com.facebook.soloader.DirectorySoSource[root = /data/app/~~p2OAPdO9oxWj2uAeKjHxdQ==/com.airnav.radarbox-cLVncqZLofEAUaCeer-8SA==/lib/arm64 flags = 0] SoSource 1: com.facebook.soloader.DirectApkSoSource[root = /data/app/~~p2OAPdO9oxWj2uAeKjHxdQ==/com.airnav.radarbox-cLVncqZLofEAUaCeer-8SA==/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] SoSource 4: com.facebook.soloader.DirectApkSoSource[root = /data/app/~~p2OAPdO9oxWj2uAeKjHxdQ==/com.airnav.radarbox-cLVncqZLofEAUaCeer-8SA==/split_config.arm64_v8a.apk!/lib/arm64-v8a] SoSource 5: com.facebook.soloader.DirectApkSoSource[root = /data/app/~~p2OAPdO9oxWj2uAeKjHxdQ==/com.airnav.radarbox-cLVncqZLofEAUaCeer-8SA==/split_config.pt.apk!/lib/arm64-v8a] SoSource 6: com.facebook.soloader.DirectApkSoSource[root = /data/app/~~p2OAPdO9oxWj2uAeKjHxdQ==/com.airnav.radarbox-cLVncqZLofEAUaCeer-8SA==/split_config.xxhdpi.apk!/lib/arm64-v8a] Native lib dir: /data/app/~~p2OAPdO9oxWj2uAeKjHxdQ==/com.airnav.radarbox-cLVncqZLofEAUaCeer-8SA==/lib/arm64 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.SoLoader.loadLibrary(SoLoader.java:743) at com.facebook.react.jscexecutor.JSCExecutor.loadLibrary(JSCExecutor.java:24) at com.facebook.react.jscexecutor.JSCExecutor.(JSCExecutor.java:20) at com.facebook.react.jscexecutor.JSCExecutor.loadLibrary() at com.facebook.react.ReactInstanceManagerBuilder.getDefaultJSExecutorFactory(ReactInstanceManagerBuilder.java:352) at com.facebook.react.ReactInstanceManagerBuilder.build(ReactInstanceManagerBuilder.java:319) at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:95) at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:42) at com.facebook.react.ReactDelegate.loadApp(ReactDelegate.java:104) at com.facebook.react.ReactActivityDelegate.loadApp(ReactActivityDelegate.java:91) at com.facebook.react.ReactActivityDelegate.onCreate(ReactActivityDelegate.java:86) at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:46) at com.airnav.radarbox.MainActivity.onCreate(MainActivity.java:15) at android.app.Activity.performCreate(Activity.java:8207) at android.app.Activity.performCreate(Activity.java:8191) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3808) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4011) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2325) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8633) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) ``` The root cause is: some OEM is using the libs like `libhermes.so` in vendor level. Because of the link namespace restriction, we can't use them from the vendor partition. Even it's useable, I think we shouldn't use them. It might cause some weird ABI compatible issue. ``` adb shell ls /vendor/lib64 | grep libhermes libhermes.so libhermes_bdbridge.so libhermes_cred.so ``` # Mitigation This diff reorders the soSource to make sure the system folders(/system/lib, /vendor/lib) are always at the end the soSource list. Differential Revision: D32174871 fbshipit-source-id: bc09a020305548bc48862fd6a2b0c54e1f33ddca --- java/com/facebook/soloader/SoLoader.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/java/com/facebook/soloader/SoLoader.java b/java/com/facebook/soloader/SoLoader.java index 7cd0831..353b1fc 100644 --- a/java/com/facebook/soloader/SoLoader.java +++ b/java/com/facebook/soloader/SoLoader.java @@ -329,12 +329,6 @@ private static int getApplicationSoSourceFlags() { /** Add DirectApk SoSources for disabling android:extractNativeLibs */ private static void addDirectApkSoSource(Context context, ArrayList soSources) { - DirectApkSoSource directApkSoSource = new DirectApkSoSource(context); - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "adding directApk source: " + directApkSoSource.toString()); - } - soSources.add(0, directApkSoSource); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && context.getApplicationInfo().splitSourceDirs != null) { if (Log.isLoggable(TAG, Log.DEBUG)) { @@ -345,9 +339,15 @@ private static void addDirectApkSoSource(Context context, ArrayList so if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "adding directApk source: " + splitApkSource.toString()); } - soSources.add(splitApkSource); + soSources.add(0, splitApkSource); } } + + DirectApkSoSource directApkSoSource = new DirectApkSoSource(context); + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "adding directApk source: " + directApkSoSource.toString()); + } + soSources.add(0, directApkSoSource); } /** Add a DirectorySoSource for the application's nativeLibraryDir . */