From 3d691395dd353d7ebf633db445bcc7460232aa7a Mon Sep 17 00:00:00 2001 From: Zuzanna Mroczek Date: Wed, 23 May 2018 06:51:17 -0700 Subject: [PATCH] Fix nativeLoad method error on Android P 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: https://github.com/facebook/fresco/issues/2115) - this diff fixes it. Reviewed By: erikandre Differential Revision: D8098159 fbshipit-source-id: df430028cff5941465a0f91800db55d498765a6c --- java/com/facebook/soloader/SoLoader.java | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/java/com/facebook/soloader/SoLoader.java b/java/com/facebook/soloader/SoLoader.java index 902f8b2..902b3e8 100644 --- a/java/com/facebook/soloader/SoLoader.java +++ b/java/com/facebook/soloader/SoLoader.java @@ -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); } @@ -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) {