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

Commit 931bb2a

Browse files
committed
Merge pull request #105 from Microsoft/clear-dev-bundle-cache
Clear dev bundle cache
2 parents e9410fb + 9c1a20f commit 931bb2a

File tree

1 file changed

+11
-9
lines changed
  • android/app/src/main/java/com/microsoft/codepush/react

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public class CodePush {
5353
private final String CODE_PUSH_TAG = "CodePush";
5454
private final String DOWNLOAD_PROGRESS_EVENT_NAME = "CodePushDownloadProgress";
5555
private final String RESOURCES_BUNDLE = "resources.arsc";
56+
// 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
57+
private final String REACT_DEV_BUNDLE_CACHE_FILE_NAME = "ReactNativeDevBundle.js";
5658

5759
private CodePushPackage codePushPackage;
5860
private CodePushReactPackage codePushReactPackage;
@@ -236,6 +238,8 @@ private void initializeUpdateAfterRestart() {
236238
// Therefore, deduce that it is a broken update and rollback.
237239
rollbackPackage();
238240
} else {
241+
// Clear the React dev bundle cache so that new updates can be loaded.
242+
clearReactDevBundleCache();
239243
// Mark that we tried to initialize the new update, so that if it crashes,
240244
// we will know that we need to rollback when the app next starts.
241245
savePendingUpdate(pendingUpdate.getString(PENDING_UPDATE_HASH_KEY),
@@ -248,20 +252,18 @@ private void initializeUpdateAfterRestart() {
248252
}
249253
}
250254

255+
private void clearReactDevBundleCache() {
256+
File cachedDevBundle = new File(this.applicationContext.getFilesDir(), REACT_DEV_BUNDLE_CACHE_FILE_NAME);
257+
if (cachedDevBundle.exists()) {
258+
cachedDevBundle.delete();
259+
}
260+
}
261+
251262
private class CodePushNativeModule extends ReactContextBaseJavaModule {
252263

253264
private LifecycleEventListener lifecycleEventListener = null;
254-
private static final String JS_BUNDLE_FILE_NAME = "ReactNativeDevBundle.js";
255-
256-
private void clearReactDevBundleCache() {
257-
File cachedDevBundle = new File(getReactApplicationContext().getFilesDir(), JS_BUNDLE_FILE_NAME);
258-
if (cachedDevBundle.exists()) {
259-
cachedDevBundle.delete();
260-
}
261-
}
262265

263266
private void loadBundle() {
264-
clearReactDevBundleCache();
265267
Intent intent = mainActivity.getIntent();
266268
mainActivity.finish();
267269
mainActivity.startActivity(intent);

0 commit comments

Comments
 (0)