From 0cc1ecdcf627503adae27a4777c4159fc96c333e Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Wed, 6 Apr 2016 16:50:09 -0700 Subject: [PATCH] Fix clearing dev cache on reload --- .../microsoft/codepush/react/CodePush.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index f202cec..62cf129 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -65,9 +65,6 @@ public class CodePush implements ReactPackage { private final String PENDING_UPDATE_KEY = "CODE_PUSH_PENDING_UPDATE"; private final String RESOURCES_BUNDLE = "resources.arsc"; - // This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78 - private final String REACT_DEV_BUNDLE_CACHE_FILE_NAME = "ReactNativeDevBundle.js"; - // Helper classes. private CodePushNativeModule codePushNativeModule; private CodePushPackage codePushPackage; @@ -112,13 +109,6 @@ public class CodePush implements ReactPackage { currentInstance = this; } - - private void clearReactDevBundleCache() { - File cachedDevBundle = new File(this.applicationContext.getFilesDir(), REACT_DEV_BUNDLE_CACHE_FILE_NAME); - if (cachedDevBundle.exists()) { - cachedDevBundle.delete(); - } - } private long getBinaryResourcesModifiedTime() { ZipFile applicationFile = null; @@ -243,10 +233,6 @@ public class CodePush implements ReactPackage { needToReportRollback = true; rollbackPackage(); } else { - // Clear the React dev bundle cache so that new updates can be loaded. - if (this.isDebugMode) { - clearReactDevBundleCache(); - } // Mark that we tried to initialize the new update, so that if it crashes, // we will know that we need to rollback when the app next starts. savePendingUpdate(pendingUpdate.getString(PENDING_UPDATE_HASH_KEY), @@ -384,6 +370,14 @@ public class CodePush implements ReactPackage { CodePush.this.initializeUpdateAfterRestart(); } + private void clearReactDevBundleCache() { + // This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78 + File cachedDevBundle = new File(CodePush.this.applicationContext.getFilesDir(), "ReactNativeDevBundle.js"); + if (cachedDevBundle.exists()) { + cachedDevBundle.delete(); + } + } + private void loadBundleLegacy() { Intent intent = mainActivity.getIntent(); mainActivity.finish(); @@ -393,6 +387,11 @@ public class CodePush implements ReactPackage { } private void loadBundle() { + // Clear the React dev bundle cache so that new updates can be loaded. + if (CodePush.this.isDebugMode) { + clearReactDevBundleCache(); + } + try { // #1) Get the private ReactInstanceManager, which is what includes // the logic to reload the current React context.