From 5da8e80ef8cfc1d44b7593c0f8582c8dc2f7a00c Mon Sep 17 00:00:00 2001 From: Adrian Catana Date: Thu, 14 Mar 2024 06:02:34 -0700 Subject: [PATCH] Rely on system loader for Android 7+ Summary: See my previous explanation at D45354649. I believe the hack doees not work and is actually not needed for Android 7+ builds. Reviewed By: danjin250 Differential Revision: D50320564 fbshipit-source-id: 008b8e6f6f9055cda2a83e5409fe2937502e3094 --- .../facebook/soloader/SoFileLoaderImpl.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/java/com/facebook/soloader/SoFileLoaderImpl.java b/java/com/facebook/soloader/SoFileLoaderImpl.java index 0e4bfee..5a140df 100644 --- a/java/com/facebook/soloader/SoFileLoaderImpl.java +++ b/java/com/facebook/soloader/SoFileLoaderImpl.java @@ -16,6 +16,7 @@ package com.facebook.soloader; +import android.os.Build; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -30,12 +31,19 @@ public class SoFileLoaderImpl implements SoFileLoader { private static final String TAG = "SoFileLoaderImpl"; - private final Runtime mRuntime; + @Nullable private final Runtime mRuntime; @Nullable private final Method mNativeLoadRuntimeMethod; @Nullable private final String mLocalLdLibraryPath; @Nullable private final String mLocalLdLibraryPathNoZips; public SoFileLoaderImpl() { + if (Build.VERSION.SDK_INT >= 24) { + mRuntime = null; + mNativeLoadRuntimeMethod = null; + mLocalLdLibraryPath = null; + mLocalLdLibraryPathNoZips = null; + return; + } mRuntime = Runtime.getRuntime(); mNativeLoadRuntimeMethod = SysUtil.getNativeLoadRuntimeMethod(); mLocalLdLibraryPath = @@ -51,8 +59,8 @@ public void loadBytes(String pathName, ElfByteChannel bytes, int loadFlags) { @Override public void load(final String pathToSoFile, final int loadFlags) { if (mNativeLoadRuntimeMethod == null) { - // nativeLoad() version with LD_LIBRARY_PATH override is not available, fallback to standard - // loader. + // nativeLoad() version with LD_LIBRARY_PATH override is not available, + // or not needed (Android 7+), fallback to standard loader. System.load(pathToSoFile); return; } @@ -63,7 +71,6 @@ public void load(final String pathToSoFile, final int loadFlags) { try { // nativeLoad should be synchronized so there's only one // LD_LIBRARY_PATH in use regardless of how many ClassLoaders are in the system - // https://android.googlesource.com/platform/libcore/+/refs/tags/android-8.0.0_r45/ojluni/src/main/java/java/lang/Runtime.java#1103 synchronized (mRuntime) { errorMessage = (String) @@ -76,8 +83,7 @@ public void load(final String pathToSoFile, final int loadFlags) { } } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // Throw an SoLoaderULError to try to recover from the state - errorMessage = - "nativeLoad() error during invocation for " + pathToSoFile + ": " + errorMessage; + errorMessage = "nativeLoad() error during invocation for " + pathToSoFile + ": " + e; throw new RuntimeException(errorMessage); } finally { if (errorMessage != null) {