Skip to content

Commit

Permalink
Fixed issue 197.
Browse files Browse the repository at this point in the history
showing NoSuchMethodException on Android P when initialing the SoLoader
facebookarchive#197
Reference:
facebook/SoLoader@3d69139
  • Loading branch information
yidinghe committed Jan 18, 2019
1 parent f73541e commit 3d5910c
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions first-party/soloader/SoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,26 @@ private static synchronized void initSoLoader(@Nullable SoFileLoader soFileLoade
sSoFileLoader = new SoFileLoader() {
@Override
public void load(final String pathToSoFile, final int loadFlags) {
String error = null;
if (hasNativeLoadMethod) {
final boolean inZip = (loadFlags & SOLOADER_LOOK_IN_ZIP) == SOLOADER_LOOK_IN_ZIP;
final String path = inZip ? localLdLibraryPath : localLdLibraryPathNoZips;
try {
synchronized (runtime) {
String error = (String)nativeLoadRuntimeMethod.invoke(
runtime,
pathToSoFile,
SoLoader.class.getClassLoader(),
path);
error =
// the third argument of nativeLoad method was removed in Android P API
Build.VERSION.SDK_INT <= 27
? (String)
nativeLoadRuntimeMethod.invoke(
runtime, pathToSoFile, SoLoader.class.getClassLoader(), path)
: (String)
nativeLoadRuntimeMethod.invoke(
runtime, pathToSoFile, SoLoader.class.getClassLoader());
if (error != null) {
throw new UnsatisfiedLinkError(error);
}
}
} catch (IllegalAccessException
} catch (IllegalAccessException
| IllegalArgumentException
| InvocationTargetException e) {
final String errMsg = "Error: Cannot load " + pathToSoFile;
Expand All @@ -292,9 +297,15 @@ private static Method getNativeLoadRuntimeMethod() {
}

try {
final Method method =
Runtime.class
.getDeclaredMethod("nativeLoad", String.class, ClassLoader.class, String.class);
final Method method;
if (Build.VERSION.SDK_INT <= 27) {
method =
Runtime.class.getDeclaredMethod(
"nativeLoad", String.class, ClassLoader.class, String.class);
} else {
method = Runtime.class.getDeclaredMethod("nativeLoad", String.class, ClassLoader.class);
}

method.setAccessible(true);
return method;
} catch (final NoSuchMethodException | SecurityException e) {
Expand Down

0 comments on commit 3d5910c

Please sign in to comment.