Skip to content

Commit 28d8a12

Browse files
committed
add android expo bundle load support
1 parent 25dde87 commit 28d8a12

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ private void setJSBundle(ReactHostDelegate reactHostDelegate, String latestJSBun
152152
Field bundleLoaderField = reactHostDelegate.getClass().getDeclaredField("jsBundleLoader");
153153
bundleLoaderField.setAccessible(true);
154154
bundleLoaderField.set(reactHostDelegate, latestJSBundleLoader);
155-
} catch (Exception e) {
155+
}
156+
catch (NoSuchFieldException noSuchFileFound) {
157+
// Ignore this error for Expo
158+
}
159+
catch (Exception e) {
156160
CodePushUtils.log("Unable to set JSBundle of ReactHostDelegate - CodePush may not support this version of React Native");
157161
throw new IllegalAccessException("Could not setJSBundle");
158162
}
@@ -182,13 +186,23 @@ private void loadBundle() {
182186
// logic to reload the current React context.
183187
final ReactHost reactHost = resolveReactHost();
184188
if (reactHost == null) {
189+
loadBundleLegacy();
185190
return;
186191
}
187192

188193
String latestJSBundleFile = mCodePush.getJSBundleFileInternal(mCodePush.getAssetsBundleFileName());
189194

190-
// #2) Update the locally stored JS bundle file path
191-
setJSBundle(getReactHostDelegate((ReactHostImpl) reactHost), latestJSBundleFile);
195+
try {
196+
if (reactHost instanceof ReactHostImpl) {
197+
ReactHostDelegate delegate = getReactHostDelegate((ReactHostImpl) reactHost);
198+
if (delegate != null) {
199+
// #2) Update the locally stored JS bundle file path
200+
setJSBundle(delegate, latestJSBundleFile);
201+
}
202+
}
203+
} catch (Exception e) {
204+
CodePushUtils.log("Exception setJSBundle: " + e.getMessage());
205+
}
192206

193207
// #3) Get the context creation method
194208
try {

0 commit comments

Comments
 (0)