diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java index f574f81c41..3ae051fbfe 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java @@ -373,31 +373,28 @@ public class ReactInstanceManagerBuilder { private JavaScriptExecutorFactory getDefaultJSExecutorFactory( String appName, String deviceName, Context applicationContext) { - // Relying solely on try catch block and loading jsc even when - // project is using hermes can lead to launch-time crashes especially in - // monorepo architectures and hybrid apps using both native android - // and react native. - // So we can use the value of enableHermes received by the constructor - // to decide which library to load at launch - - // if nothing is specified, use old loading method - // else load the required engine + initializeSoLoaderIfNecessary(applicationContext); + // Hermes has been enabled by default in OSS since React Native 0.70. + // If the user hasn't specified a JSEngineResolutionAlgorithm, + // we attempt to load Hermes first, and fallback to JSC if we can't resolve the library. if (mJSEngineResolutionAlgorithm == null) { - FLog.w( - TAG, - "You're not setting the JS Engine Resolution Algorithm. " - + "We'll try to load JSC first, and if it fails we'll fallback to Hermes"); try { - // If JSC is included, use it as normal - initializeSoLoaderIfNecessary(applicationContext); - JSCExecutor.loadLibrary(); - return new JSCExecutorFactory(appName, deviceName); - } catch (UnsatisfiedLinkError jscE) { - if (jscE.getMessage().contains("__cxa_bad_typeid")) { - throw jscE; - } HermesExecutor.loadLibrary(); return new HermesExecutorFactory(); + } catch (UnsatisfiedLinkError ignoredHermesError) { + try { + JSCExecutor.loadLibrary(); + return new JSCExecutorFactory(appName, deviceName); + } catch (UnsatisfiedLinkError jscError) { + FLog.e( + TAG, + "Unable to load neither the Hermes nor the JSC native library. " + + "Your application is not built correctly and will fail to execute"); + if (jscError.getMessage().contains("__cxa_bad_typeid")) { + throw jscError; + } + return null; + } } } else if (mJSEngineResolutionAlgorithm == JSEngineResolutionAlgorithm.HERMES) { HermesExecutor.loadLibrary();