mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix crash on HeadlessJsTaskService on old architecture (#48124)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48124 Fixes https://github.com/facebook/react-native/issues/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
This commit is contained in:
committed by
Blake Friedman
parent
d105c2c6fe
commit
d1ce8fafb6
+12
-13
@@ -179,9 +179,18 @@ public abstract class HeadlessJsTaskService extends Service implements HeadlessJ
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createReactContextAndScheduleTask(final HeadlessJsTaskConfig taskConfig) {
|
private void createReactContextAndScheduleTask(final HeadlessJsTaskConfig taskConfig) {
|
||||||
final ReactHost reactHost = getReactHost();
|
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
|
||||||
|
final ReactHost reactHost = getReactHost();
|
||||||
if (reactHost == null) { // old arch
|
reactHost.addReactInstanceEventListener(
|
||||||
|
new ReactInstanceEventListener() {
|
||||||
|
@Override
|
||||||
|
public void onReactContextInitialized(@NonNull ReactContext reactContext) {
|
||||||
|
invokeStartTask(reactContext, taskConfig);
|
||||||
|
reactHost.removeReactInstanceEventListener(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
reactHost.start();
|
||||||
|
} else {
|
||||||
final ReactInstanceManager reactInstanceManager =
|
final ReactInstanceManager reactInstanceManager =
|
||||||
getReactNativeHost().getReactInstanceManager();
|
getReactNativeHost().getReactInstanceManager();
|
||||||
|
|
||||||
@@ -194,16 +203,6 @@ public abstract class HeadlessJsTaskService extends Service implements HeadlessJ
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
reactInstanceManager.createReactContextInBackground();
|
reactInstanceManager.createReactContextInBackground();
|
||||||
} else { // new arch
|
|
||||||
reactHost.addReactInstanceEventListener(
|
|
||||||
new ReactInstanceEventListener() {
|
|
||||||
@Override
|
|
||||||
public void onReactContextInitialized(@NonNull ReactContext reactContext) {
|
|
||||||
invokeStartTask(reactContext, taskConfig);
|
|
||||||
reactHost.removeReactInstanceEventListener(this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
reactHost.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user