Skip to content

Commit

Permalink
Fix crash on HeadlessJsTaskService on old architecture
Browse files Browse the repository at this point in the history
Summary:
Fixes facebook#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

Differential Revision: D66826271
  • Loading branch information
cortinico authored and facebook-github-bot committed Dec 5, 2024
1 parent 00d5cae commit e0c6242
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,18 @@ protected ReactContext getReactContext() {
}

private void createReactContextAndScheduleTask(final HeadlessJsTaskConfig taskConfig) {
final ReactHost reactHost = getReactHost();

if (reactHost == null) { // old arch
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
final ReactHost reactHost = getReactHost();
reactHost.addReactInstanceEventListener(
new ReactInstanceEventListener() {
@Override
public void onReactContextInitialized(@NonNull ReactContext reactContext) {
invokeStartTask(reactContext, taskConfig);
reactHost.removeReactInstanceEventListener(this);
}
});
reactHost.start();
} else {
final ReactInstanceManager reactInstanceManager =
getReactNativeHost().getReactInstanceManager();

Expand All @@ -194,16 +203,6 @@ public void onReactContextInitialized(@NonNull ReactContext reactContext) {
}
});
reactInstanceManager.createReactContextInBackground();
} else { // new arch
reactHost.addReactInstanceEventListener(
new ReactInstanceEventListener() {
@Override
public void onReactContextInitialized(@NonNull ReactContext reactContext) {
invokeStartTask(reactContext, taskConfig);
reactHost.removeReactInstanceEventListener(this);
}
});
reactHost.start();
}
}
}

0 comments on commit e0c6242

Please sign in to comment.