Skip to content

Commit

Permalink
Fix crash on HeadlessJsTaskService on old architecture (#48124)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cortinico authored and facebook-github-bot committed Dec 6, 2024
1 parent ddfa212 commit 4560fc0
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,31 +179,30 @@ protected ReactContext getReactContext() {
}

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

if (reactHost == null) { // old arch
final ReactInstanceManager reactInstanceManager =
getReactNativeHost().getReactInstanceManager();

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

reactInstanceManager.addReactInstanceEventListener(
new ReactInstanceEventListener() {
@Override
public void onReactContextInitialized(@NonNull ReactContext reactContext) {
invokeStartTask(reactContext, taskConfig);
reactHost.removeReactInstanceEventListener(this);
reactInstanceManager.removeReactInstanceEventListener(this);
}
});
reactHost.start();
reactInstanceManager.createReactContextInBackground();
}
}
}

0 comments on commit 4560fc0

Please sign in to comment.