Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 0cc1ecd

Browse files
committed
Fix clearing dev cache on reload
1 parent 14a6d08 commit 0cc1ecd

File tree

1 file changed

+13
-14
lines changed
  • android/app/src/main/java/com/microsoft/codepush/react

1 file changed

+13
-14
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ public class CodePush implements ReactPackage {
6565
private final String PENDING_UPDATE_KEY = "CODE_PUSH_PENDING_UPDATE";
6666
private final String RESOURCES_BUNDLE = "resources.arsc";
6767

68-
// 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
69-
private final String REACT_DEV_BUNDLE_CACHE_FILE_NAME = "ReactNativeDevBundle.js";
70-
7168
// Helper classes.
7269
private CodePushNativeModule codePushNativeModule;
7370
private CodePushPackage codePushPackage;
@@ -112,13 +109,6 @@ public CodePush(String deploymentKey, Activity mainActivity, boolean isDebugMode
112109

113110
currentInstance = this;
114111
}
115-
116-
private void clearReactDevBundleCache() {
117-
File cachedDevBundle = new File(this.applicationContext.getFilesDir(), REACT_DEV_BUNDLE_CACHE_FILE_NAME);
118-
if (cachedDevBundle.exists()) {
119-
cachedDevBundle.delete();
120-
}
121-
}
122112

123113
private long getBinaryResourcesModifiedTime() {
124114
ZipFile applicationFile = null;
@@ -243,10 +233,6 @@ private void initializeUpdateAfterRestart() {
243233
needToReportRollback = true;
244234
rollbackPackage();
245235
} else {
246-
// Clear the React dev bundle cache so that new updates can be loaded.
247-
if (this.isDebugMode) {
248-
clearReactDevBundleCache();
249-
}
250236
// Mark that we tried to initialize the new update, so that if it crashes,
251237
// we will know that we need to rollback when the app next starts.
252238
savePendingUpdate(pendingUpdate.getString(PENDING_UPDATE_HASH_KEY),
@@ -384,6 +370,14 @@ public void initialize() {
384370
CodePush.this.initializeUpdateAfterRestart();
385371
}
386372

373+
private void clearReactDevBundleCache() {
374+
// 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
375+
File cachedDevBundle = new File(CodePush.this.applicationContext.getFilesDir(), "ReactNativeDevBundle.js");
376+
if (cachedDevBundle.exists()) {
377+
cachedDevBundle.delete();
378+
}
379+
}
380+
387381
private void loadBundleLegacy() {
388382
Intent intent = mainActivity.getIntent();
389383
mainActivity.finish();
@@ -393,6 +387,11 @@ private void loadBundleLegacy() {
393387
}
394388

395389
private void loadBundle() {
390+
// Clear the React dev bundle cache so that new updates can be loaded.
391+
if (CodePush.this.isDebugMode) {
392+
clearReactDevBundleCache();
393+
}
394+
396395
try {
397396
// #1) Get the private ReactInstanceManager, which is what includes
398397
// the logic to reload the current React context.

0 commit comments

Comments
 (0)