From b8bd4a021c1df15fa3b42f498c2d1f4119d56be7 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 1 Jun 2017 14:10:33 +0300 Subject: [PATCH] Fixed issue with [Android] restartApp() throwing exception w/ release build (#861) * Fixed issue with error on parsing plist path See https://github.com/Microsoft/react-native-code-push/issues/534#issuecomment-302069326 for details * Fixed issue with [Android] restartApp() throwing exception w/ release build https://github.com/Microsoft/react-native-code-push/issues/847 * Changed return value to null for getUpdateMetadata instead of empty string In accordance with docs and https://github.com/Microsoft/react-native-code-push/issues/862 * Code refactoring: moved variable assignment out of loop --- .../microsoft/codepush/react/CodePushNativeModule.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java index 0ae0b0b..e8ccd9f 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java @@ -105,10 +105,12 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { Field bundleLoaderField = instanceManager.getClass().getDeclaredField("mBundleLoader"); Class jsBundleLoaderClass = Class.forName("com.facebook.react.cxxbridge.JSBundleLoader"); Method createFileLoaderMethod = null; + String createFileLoaderMethodName = latestJSBundleFile.toLowerCase().startsWith("assets://") + ? "createAssetLoader" : "createFileLoader"; Method[] methods = jsBundleLoaderClass.getDeclaredMethods(); - for (Method method : methods) { - if (method.getName().equals("createFileLoader")) { + for (Method method : methods) { + if (method.getName().equals(createFileLoaderMethodName)) { createFileLoaderMethod = method; break; } @@ -125,7 +127,7 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { // RN >= v0.34 latestJSBundleLoader = createFileLoaderMethod.invoke(jsBundleLoaderClass, latestJSBundleFile); } else if (numParameters == 2) { - // RN >= v0.31 && RN < v0.34 + // RN >= v0.31 && RN < v0.34 or AssetLoader instance latestJSBundleLoader = createFileLoaderMethod.invoke(jsBundleLoaderClass, getReactApplicationContext(), latestJSBundleFile); } else { throw new NoSuchMethodException("Could not find a recognized 'createFileLoader' method");