Skip to content

Commit 3ee058c

Browse files
javachefacebook-github-bot
authored andcommitted
Disable legacy Hermes executor creation (#59753)
Summary: Keep `HermesExecutor.loadLibrary()` as a compatibility no-op and reject `HermesExecutorFactory.create()` with New Architecture migration guidance. Changelog: [Android][Breaking] - Disable legacy Hermes executor creation. Differential Revision: D129045580
1 parent 3d3a339 commit 3ee058c

3 files changed

Lines changed: 48 additions & 21 deletions

File tree

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.kt‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,15 @@ package com.facebook.hermes.reactexecutor
1010
import com.facebook.jni.HybridData
1111
import com.facebook.jni.annotations.DoNotStrip
1212
import com.facebook.react.bridge.JavaScriptExecutor
13-
import com.facebook.react.common.build.ReactBuildConfig
14-
import com.facebook.soloader.SoLoader
1513

1614
public class HermesExecutor internal constructor(enableDebugger: Boolean, debuggerName: String) :
1715
JavaScriptExecutor(initHybridDefaultConfig(enableDebugger, debuggerName)) {
1816

19-
override fun getName(): String = "HermesExecutor$mode"
17+
override fun getName(): String = "HermesExecutor"
2018

2119
public companion object {
22-
private var mode: String? = null
23-
24-
init {
25-
loadLibrary()
26-
}
27-
28-
@JvmStatic
29-
@Throws(UnsatisfiedLinkError::class)
30-
public fun loadLibrary() {
31-
if (mode == null) {
32-
// libhermesvm must be loaded explicitly to invoke its JNI_OnLoad.
33-
SoLoader.loadLibrary("hermesvm")
34-
SoLoader.loadLibrary("hermes_executor")
35-
// libhermes_executor is built differently for Debug & Release so we load the proper mode.
36-
mode = if (ReactBuildConfig.DEBUG) "Debug" else "Release"
37-
}
38-
}
20+
/** Retained for compatibility; this method no longer loads native libraries. */
21+
@JvmStatic public fun loadLibrary() {}
3922

4023
@DoNotStrip
4124
@JvmStatic

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.kt‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@ public class HermesExecutorFactory : JavaScriptExecutorFactory {
2525
this.debuggerName = debuggerName
2626
}
2727

28-
override fun create(): JavaScriptExecutor = HermesExecutor(enableDebugger, debuggerName)
28+
/**
29+
* Compatibility factory for the unsupported legacy Hermes executor.
30+
*
31+
* @throws UnsupportedOperationException when creating an executor; use the New Architecture
32+
* runtime instead.
33+
*/
34+
override fun create(): JavaScriptExecutor {
35+
throw UnsupportedOperationException(
36+
"HermesExecutorFactory is no longer supported. Use the New Architecture runtime instead.",
37+
)
38+
}
2939

3040
override fun startSamplingProfiler() {
3141
enable()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.hermes.reactexecutor
9+
10+
import org.assertj.core.api.Assertions.assertThatThrownBy
11+
import org.junit.Test
12+
13+
class HermesExecutorFactoryTest {
14+
@Test
15+
fun loadLibraryIsNoOp() {
16+
HermesExecutor.loadLibrary()
17+
HermesExecutor.loadLibrary()
18+
}
19+
20+
@Test
21+
fun createIsUnsupported() {
22+
val factory = HermesExecutorFactory()
23+
factory.setEnableDebugger(false)
24+
factory.setDebuggerName("test")
25+
26+
repeat(2) {
27+
assertThatThrownBy { factory.create() }
28+
.isInstanceOf(UnsupportedOperationException::class.java)
29+
.hasMessage(
30+
"HermesExecutorFactory is no longer supported. Use the New Architecture runtime instead.",
31+
)
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)