Skip to content

Commit 0954c1d

Browse files
cortinicofacebook-github-bot
authored andcommitted
Remove and cleanup JSEngineResolutionAlgorithm (facebook#51931)
Summary: Pull Request resolved: facebook#51931 This cleans up the whole `JSEngineResolutionAlgorithm` and all the API related to it. As now we offer support only for Hermes and JSC is provided via a community package. This is breaking as it affects Expo, but I'll reach out to Kudo to make sure this is integrated properly. No other breakages other than this. Changelog: [Android] [Removed] - Remove and cleanup JSEngineResolutionAlgorithm Reviewed By: mdvacca Differential Revision: D76337620 fbshipit-source-id: e43d5d1164f368f5fa395971bca9c05821492dfe
1 parent 0e1a94a commit 0954c1d

File tree

7 files changed

+20
-93
lines changed

7 files changed

+20
-93
lines changed

packages/helloworld/android/app/src/main/java/com/helloworld/MainApplication.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class MainApplication : Application(), ReactApplication {
3232
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
3333

3434
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
35-
override val isHermesEnabled: Boolean = true
3635
}
3736

3837
override val reactHost: ReactHost

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ public final class com/facebook/react/HeadlessJsTaskService$Companion {
4646
public final fun acquireWakeLockNow (Landroid/content/Context;)V
4747
}
4848

49-
public final class com/facebook/react/JSEngineResolutionAlgorithm : java/lang/Enum {
50-
public static final field HERMES Lcom/facebook/react/JSEngineResolutionAlgorithm;
51-
public static final field JSC Lcom/facebook/react/JSEngineResolutionAlgorithm;
52-
public static fun getEntries ()Lkotlin/enums/EnumEntries;
53-
public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/JSEngineResolutionAlgorithm;
54-
public static fun values ()[Lcom/facebook/react/JSEngineResolutionAlgorithm;
55-
}
56-
5749
public abstract class com/facebook/react/LazyReactPackage : com/facebook/react/ReactPackage {
5850
public fun <init> ()V
5951
public fun createNativeModules (Lcom/facebook/react/bridge/ReactApplicationContext;)Ljava/util/List;
@@ -315,7 +307,6 @@ public class com/facebook/react/ReactInstanceManagerBuilder {
315307
public fun setInitialLifecycleState (Lcom/facebook/react/common/LifecycleState;)Lcom/facebook/react/ReactInstanceManagerBuilder;
316308
public fun setJSBundleFile (Ljava/lang/String;)Lcom/facebook/react/ReactInstanceManagerBuilder;
317309
public fun setJSBundleLoader (Lcom/facebook/react/bridge/JSBundleLoader;)Lcom/facebook/react/ReactInstanceManagerBuilder;
318-
public fun setJSEngineResolutionAlgorithm (Lcom/facebook/react/JSEngineResolutionAlgorithm;)Lcom/facebook/react/ReactInstanceManagerBuilder;
319310
public fun setJSExceptionHandler (Lcom/facebook/react/bridge/JSExceptionHandler;)Lcom/facebook/react/ReactInstanceManagerBuilder;
320311
public fun setJSMainModulePath (Ljava/lang/String;)Lcom/facebook/react/ReactInstanceManagerBuilder;
321312
public fun setJavaScriptExecutorFactory (Lcom/facebook/react/bridge/JavaScriptExecutorFactory;)Lcom/facebook/react/ReactInstanceManagerBuilder;
@@ -343,7 +334,6 @@ public abstract class com/facebook/react/ReactNativeHost {
343334
protected fun getDevLoadingViewManager ()Lcom/facebook/react/devsupport/interfaces/DevLoadingViewManager;
344335
protected fun getDevSupportManagerFactory ()Lcom/facebook/react/devsupport/DevSupportManagerFactory;
345336
protected fun getJSBundleFile ()Ljava/lang/String;
346-
protected fun getJSEngineResolutionAlgorithm ()Lcom/facebook/react/JSEngineResolutionAlgorithm;
347337
protected fun getJSExceptionHandler ()Lcom/facebook/react/bridge/JSExceptionHandler;
348338
protected fun getJSMainModuleName ()Ljava/lang/String;
349339
protected fun getJavaScriptExecutorFactory ()Lcom/facebook/react/bridge/JavaScriptExecutorFactory;
@@ -1902,10 +1892,9 @@ public final class com/facebook/react/defaults/DefaultReactHost {
19021892
public abstract class com/facebook/react/defaults/DefaultReactNativeHost : com/facebook/react/ReactNativeHost {
19031893
protected fun <init> (Landroid/app/Application;)V
19041894
public fun clear ()V
1905-
protected fun getJSEngineResolutionAlgorithm ()Lcom/facebook/react/JSEngineResolutionAlgorithm;
19061895
protected fun getReactPackageTurboModuleManagerDelegateBuilder ()Lcom/facebook/react/ReactPackageTurboModuleManagerDelegate$Builder;
19071896
protected fun getUIManagerProvider ()Lcom/facebook/react/bridge/UIManagerProvider;
1908-
protected fun isHermesEnabled ()Ljava/lang/Boolean;
1897+
protected fun isHermesEnabled ()Z
19091898
protected fun isNewArchEnabled ()Z
19101899
}
19111900

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

Lines changed: 0 additions & 22 deletions
This file was deleted.

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

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public class ReactInstanceManagerBuilder {
8181
private @Nullable ReactPackageTurboModuleManagerDelegate.Builder mTMMDelegateBuilder;
8282
private @Nullable SurfaceDelegateFactory mSurfaceDelegateFactory;
8383
private @Nullable DevLoadingViewManager mDevLoadingViewManager;
84-
private @Nullable JSEngineResolutionAlgorithm mJSEngineResolutionAlgorithm = null;
8584
private @Nullable ChoreographerProvider mChoreographerProvider = null;
8685
private @Nullable PausedInDebuggerOverlayManager mPausedInDebuggerOverlayManager = null;
8786

@@ -135,16 +134,6 @@ public ReactInstanceManagerBuilder setJSBundleLoader(JSBundleLoader jsBundleLoad
135134
return this;
136135
}
137136

138-
/**
139-
* Sets the JS Engine to load as either Hermes or JSC. If not set, the default is JSC with a
140-
* Hermes fallback.
141-
*/
142-
public ReactInstanceManagerBuilder setJSEngineResolutionAlgorithm(
143-
@Nullable JSEngineResolutionAlgorithm jsEngineResolutionAlgorithm) {
144-
mJSEngineResolutionAlgorithm = jsEngineResolutionAlgorithm;
145-
return this;
146-
}
147-
148137
/**
149138
* Path to your app's main module on Metro. This is used when reloading JS during development. All
150139
* paths are relative to the root folder the packager is serving files from. Examples: {@code
@@ -389,33 +378,24 @@ private JavaScriptExecutorFactory getDefaultJSExecutorFactory(
389378

390379
initializeSoLoaderIfNecessary(applicationContext);
391380
// Hermes has been enabled by default in OSS since React Native 0.70.
392-
// If the user hasn't specified a JSEngineResolutionAlgorithm,
393-
// we attempt to load Hermes first, and fallback to JSC if we can't resolve the library.
394-
if (mJSEngineResolutionAlgorithm == null) {
381+
// Here we attempt to load Hermes first, and fallback to JSC if we can't resolve the library.
382+
try {
383+
HermesExecutor.loadLibrary();
384+
return new HermesExecutorFactory();
385+
} catch (UnsatisfiedLinkError ignoredHermesError) {
395386
try {
396-
HermesExecutor.loadLibrary();
397-
return new HermesExecutorFactory();
398-
} catch (UnsatisfiedLinkError ignoredHermesError) {
399-
try {
400-
JSCExecutor.loadLibrary();
401-
return new JSCExecutorFactory(appName, deviceName);
402-
} catch (UnsatisfiedLinkError jscError) {
403-
FLog.e(
404-
TAG,
405-
"Unable to load neither the Hermes nor the JSC native library. "
406-
+ "Your application is not built correctly and will fail to execute");
407-
if (jscError.getMessage().contains("__cxa_bad_typeid")) {
408-
throw jscError;
409-
}
410-
return null;
387+
JSCExecutor.loadLibrary();
388+
return new JSCExecutorFactory(appName, deviceName);
389+
} catch (UnsatisfiedLinkError jscError) {
390+
FLog.e(
391+
TAG,
392+
"Unable to load neither the Hermes nor the JSC native library. "
393+
+ "Your application is not built correctly and will fail to execute");
394+
if (jscError.getMessage().contains("__cxa_bad_typeid")) {
395+
throw jscError;
411396
}
397+
return null;
412398
}
413-
} else if (mJSEngineResolutionAlgorithm == JSEngineResolutionAlgorithm.HERMES) {
414-
HermesExecutor.loadLibrary();
415-
return new HermesExecutorFactory();
416-
} else {
417-
JSCExecutor.loadLibrary();
418-
return new JSCExecutorFactory(appName, deviceName);
419399
}
420400
}
421401
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ protected ReactInstanceManagerBuilder getBaseReactInstanceManagerBuilder() {
114114
.setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
115115
.setReactPackageTurboModuleManagerDelegateBuilder(
116116
getReactPackageTurboModuleManagerDelegateBuilder())
117-
.setJSEngineResolutionAlgorithm(getJSEngineResolutionAlgorithm())
118117
.setChoreographerProvider(getChoreographerProvider())
119118
.setPausedInDebuggerOverlayManager(getPausedInDebuggerOverlayManager());
120119

@@ -241,14 +240,6 @@ protected String getJSMainModuleName() {
241240
*/
242241
protected abstract List<ReactPackage> getPackages();
243242

244-
/**
245-
* Returns the {@link JSEngineResolutionAlgorithm} to be used when loading the JS engine. If null,
246-
* will try to load JSC first and fallback to Hermes if JSC is not available.
247-
*/
248-
protected @Nullable JSEngineResolutionAlgorithm getJSEngineResolutionAlgorithm() {
249-
return null;
250-
}
251-
252243
/**
253244
* Returns a custom implementation of ChoreographerProvider to be used this host. If null - React
254245
* will use default direct android.view.Choreographer-based provider.

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactNativeHost.kt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package com.facebook.react.defaults
99

1010
import android.app.Application
1111
import android.content.Context
12-
import com.facebook.react.JSEngineResolutionAlgorithm
1312
import com.facebook.react.ReactHost
1413
import com.facebook.react.ReactNativeHost
1514
import com.facebook.react.ReactPackageTurboModuleManagerDelegate
@@ -72,13 +71,6 @@ protected constructor(
7271
null
7372
}
7473

75-
override fun getJSEngineResolutionAlgorithm(): JSEngineResolutionAlgorithm? =
76-
when (isHermesEnabled) {
77-
true -> JSEngineResolutionAlgorithm.HERMES
78-
false -> JSEngineResolutionAlgorithm.JSC
79-
null -> null
80-
}
81-
8274
override fun clear() {
8375
super.clear()
8476
DefaultReactHost.invalidate()
@@ -99,11 +91,10 @@ protected constructor(
9991
* Returns whether the user wants to use Hermes.
10092
*
10193
* If true, the app will load the Hermes engine, and fail if not found. If false, the app will
102-
* load the JSC engine, and fail if not found. If null, the app will attempt to load JSC first and
103-
* fallback to Hermes if not found.
94+
* load the JSC engine, and fail if not found.
10495
*/
105-
protected open val isHermesEnabled: Boolean?
106-
get() = null
96+
protected open val isHermesEnabled: Boolean
97+
get() = true
10798

10899
/**
109100
* Converts this [ReactNativeHost] (bridge-mode) to a [ReactHost] (bridgeless-mode).
@@ -116,7 +107,7 @@ protected constructor(
116107
jsRuntimeFactory: JSRuntimeFactory? = null
117108
): ReactHost {
118109
val concreteJSRuntimeFactory =
119-
jsRuntimeFactory ?: if (isHermesEnabled == false) JSCInstance() else HermesInstance()
110+
jsRuntimeFactory ?: if (isHermesEnabled) HermesInstance() else JSCInstance()
120111
return DefaultReactHost.getDefaultReactHost(
121112
context,
122113
packages,

packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ internal class RNTesterApplication : Application(), ReactApplication {
114114
}
115115

116116
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
117-
override val isHermesEnabled: Boolean = true
118117
}
119118
}
120119

0 commit comments

Comments
 (0)