Skip to content

Commit d81be20

Browse files
cortinicoblakef
authored andcommitted
Fix crash on HeadlessJsTaskService on old architecture (#48124)
Summary: Pull Request resolved: #48124 Fixes #47592 The logic in HeadlessJsTaskService is broken. We should not check whether `getReactContext` is null or not. Instead we should use the `enableBridgelessArchitecture` feature flag to understand if New Architecture was enabled or not. The problem we were having is that `HeadlessJsTaskService` was attempting to load the New Architecture even if the user would have it turned off. The Service would then die attempting to load `libappmodules.so` which was correctly missing. Changelog: [Android] [Fixed] - Fix crash on HeadlessJsTaskService on old architecture Reviewed By: javache Differential Revision: D66826271 fbshipit-source-id: 2b8418e0b01b65014cdbfd0ec2f843420a15f9db
1 parent 6cde3df commit d81be20

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,31 +179,30 @@ protected ReactContext getReactContext() {
179179
}
180180

181181
private void createReactContextAndScheduleTask(final HeadlessJsTaskConfig taskConfig) {
182-
final ReactHost reactHost = getReactHost();
183-
184-
if (reactHost == null) { // old arch
185-
final ReactInstanceManager reactInstanceManager =
186-
getReactNativeHost().getReactInstanceManager();
187-
188-
reactInstanceManager.addReactInstanceEventListener(
182+
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
183+
final ReactHost reactHost = getReactHost();
184+
reactHost.addReactInstanceEventListener(
189185
new ReactInstanceEventListener() {
190186
@Override
191187
public void onReactContextInitialized(@NonNull ReactContext reactContext) {
192188
invokeStartTask(reactContext, taskConfig);
193-
reactInstanceManager.removeReactInstanceEventListener(this);
189+
reactHost.removeReactInstanceEventListener(this);
194190
}
195191
});
196-
reactInstanceManager.createReactContextInBackground();
197-
} else { // new arch
198-
reactHost.addReactInstanceEventListener(
192+
reactHost.start();
193+
} else {
194+
final ReactInstanceManager reactInstanceManager =
195+
getReactNativeHost().getReactInstanceManager();
196+
197+
reactInstanceManager.addReactInstanceEventListener(
199198
new ReactInstanceEventListener() {
200199
@Override
201200
public void onReactContextInitialized(@NonNull ReactContext reactContext) {
202201
invokeStartTask(reactContext, taskConfig);
203-
reactHost.removeReactInstanceEventListener(this);
202+
reactInstanceManager.removeReactInstanceEventListener(this);
204203
}
205204
});
206-
reactHost.start();
205+
reactInstanceManager.createReactContextInBackground();
207206
}
208207
}
209208
}

0 commit comments

Comments
 (0)