Skip to content

Commit

Permalink
Fix nativeLoad method error on Android P
Browse files Browse the repository at this point in the history
Summary: The nativeLoad method doesn't have the third argument in Android P, so it's causing an error in calling it from SoLoader (github issue for fresco: facebook/fresco#2115) - this diff fixes it.

Reviewed By: erikandre

Differential Revision: D8098159

fbshipit-source-id: df430028cff5941465a0f91800db55d498765a6c
  • Loading branch information
zmroczek authored and facebook-github-bot committed May 23, 2018
1 parent e375486 commit 3d69139
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions java/com/facebook/soloader/SoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,14 @@ public void load(final String pathToSoFile, final int loadFlags) {
try {
synchronized (runtime) {
error =
(String)
nativeLoadRuntimeMethod.invoke(
runtime, pathToSoFile, SoLoader.class.getClassLoader(), path);
// 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);
}
Expand Down Expand Up @@ -378,9 +383,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 3d69139

Please sign in to comment.