1313import com .facebook .react .ReactDelegate ;
1414import com .facebook .react .ReactHost ;
1515import com .facebook .react .ReactActivity ;
16+ import com .facebook .react .ReactInstanceManager ;
1617import com .facebook .react .ReactRootView ;
1718import com .facebook .react .bridge .Arguments ;
1819import com .facebook .react .bridge .JSBundleLoader ;
@@ -125,7 +126,9 @@ private void setJSBundle(String latestJSBundleFile) throws IllegalAccessExceptio
125126
126127 ReactHost reactHost = resolveReactHost ();
127128 if (reactHost == null ) {
129+ CodePushUtils .log ("Unable to resolve ReactHost" );
128130 // Bridge, Old Architecture
131+ setJSBundleLoaderBridge (latestJSBundleLoader );
129132 return ;
130133 }
131134
@@ -137,6 +140,15 @@ private void setJSBundle(String latestJSBundleFile) throws IllegalAccessExceptio
137140 }
138141 }
139142
143+ private void setJSBundleLoaderBridge (JSBundleLoader latestJSBundleLoader ) throws NoSuchFieldException , IllegalAccessException {
144+ ReactDelegate reactDelegate = resolveReactDelegate ();
145+ assert reactDelegate != null ;
146+ ReactInstanceManager instanceManager = reactDelegate .getReactInstanceManager ();
147+ Field bundleLoaderField = instanceManager .getClass ().getDeclaredField ("mBundleLoader" );
148+ bundleLoaderField .setAccessible (true );
149+ bundleLoaderField .set (instanceManager , latestJSBundleLoader );
150+ }
151+
140152 @ OptIn (markerClass = UnstableReactNativeAPI .class )
141153 private void setJSBundleLoaderBridgeless (ReactHost reactHost , JSBundleLoader latestJSBundleLoader ) throws NoSuchFieldException , IllegalAccessException {
142154 Field reactHostDelegateField ;
@@ -222,23 +234,11 @@ private ReactDelegate resolveReactDelegate() {
222234 private ReactHost resolveReactHost () {
223235 ReactDelegate reactDelegate = resolveReactDelegate ();
224236 if (reactDelegate == null ) {
237+ CodePushUtils .log ("Unable to resolve ReactDelegate" );
225238 return null ;
226239 }
227240
228- try {
229- Field reactHostField ;
230- try {
231- // RN < 0.81
232- reactHostField = reactDelegate .getClass ().getDeclaredField ("mReactHost" );
233- } catch (NoSuchFieldException e ) {
234- // RN >= 0.81
235- reactHostField = reactDelegate .getClass ().getDeclaredField ("reactHost" );
236- }
237- reactHostField .setAccessible (true );
238- return (ReactHost ) reactHostField .get (reactDelegate );
239- } catch (Exception e ) {
240- return null ;
241- }
241+ return reactDelegate .getReactHost ();
242242 }
243243
244244 private void restartAppInternal (boolean onlyIfUpdateIsPending ) {
0 commit comments