Skip to content

Commit 5a1228c

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Remove hermesV1Enabled Gradle property and simplify Hermes version resolution (facebook#56733)
Summary: - Remove `hermesV1Enabled` / `react.hermesV1Enabled` Gradle property and all branching it controls - Rename `HERMES_V1_VERSION_NAME` to `HERMES_VERSION_NAME` in `version.properties` - Remove `hermesV1Enabled` from `PrivateReactExtension`, `ProjectUtils`, `PropertyUtils`, `ReactPlugin` - Simplify `DependencyUtils.Coordinates` to single Hermes version - Make `-DHERMESVM_HEAP_HV_MODE=HEAP_HV_PREFER32` CMake flag unconditional - Remove `-DHERMES_V1_ENABLED=1` CMake argument from `ReactAndroid` and Fantom builds - Delete `hermesV1Enabled=true` from `gradle.properties` - Update all Gradle plugin tests ## Changelog: [Android][Removed] - Remove hermesV1Enabled and simplify the code ## Test plan - [x] Gradle plugin: `./gradlew -p packages/gradle-plugin build` — BUILD SUCCESSFUL, all tests pass - [x] Android: `./gradlew :packages:rn-tester:android:app:assembleDebug` — BUILD SUCCESSFUL Reviewed By: cortinico Differential Revision: D104244582
1 parent 1ed1f23 commit 5a1228c

15 files changed

Lines changed: 54 additions & 347 deletions

File tree

build.gradle.kts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ if (project.findProperty("react.internal.useHermesStable")?.toString()?.toBoolea
118118
val hermesVersionPropertiesFile =
119119
rootProject.file("./packages/react-native/sdks/hermes-engine/version.properties")
120120
hermesVersionPropertiesFile.inputStream().use { hermesVersions.load(it) }
121-
val selectedHermesVersion = hermesVersions["HERMES_V1_VERSION_NAME"] as String
121+
val selectedHermesVersion = hermesVersions["HERMES_VERSION_NAME"] as String
122122

123123
hermesSubstitution = selectedHermesVersion to "Users opted to use stable hermes release"
124124
} else if (
@@ -137,15 +137,7 @@ if (project.findProperty("react.internal.useHermesStable")?.toString()?.toBoolea
137137
)
138138
}
139139

140-
val hermesV1Enabled = project.findProperty("hermesV1Enabled")?.toString()?.toBoolean() ?: true
141-
// Hermes V1 stable releases are published without the -SNAPSHOT suffix.
142-
// Legacy nightly builds use -SNAPSHOT.
143-
val resolvedVersion =
144-
if (hermesV1Enabled) hermesCompilerVersion else "$hermesCompilerVersion-SNAPSHOT"
145-
val reason =
146-
if (hermesV1Enabled) "Users opted to use hermes V1 stable"
147-
else "Users opted to use hermes nightly"
148-
hermesSubstitution = resolvedVersion to reason
140+
hermesSubstitution = hermesCompilerVersion to "Users opted to use hermes nightly"
149141
} else {
150142
logger.warn(
151143
"""

gradle.properties

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,3 @@ react.internal.useHermesStable=false
2424
# Controls whether to use Hermes from nightly builds. This will speed up builds
2525
# but should NOT be turned on for CI or release builds.
2626
react.internal.useHermesNightly=true
27-
28-
# Controls whether to use Hermes 1.0. Clean and rebuild when changing.
29-
hermesV1Enabled=true

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import com.facebook.react.utils.DependencyUtils.readVersionAndGroupStrings
2828
import com.facebook.react.utils.JdkConfiguratorUtils.configureJavaToolChains
2929
import com.facebook.react.utils.JsonUtils
3030
import com.facebook.react.utils.NdkConfiguratorUtils.configureReactNativeNdk
31-
import com.facebook.react.utils.ProjectUtils.isHermesV1Enabled
3231
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
32+
import com.facebook.react.utils.PropertyUtils
3333
import com.facebook.react.utils.findPackageJsonFile
3434
import java.io.File
3535
import kotlin.system.exitProcess
@@ -55,8 +55,25 @@ class ReactPlugin : Plugin<Project> {
5555
project,
5656
)
5757

58-
if (!project.rootProject.isHermesV1Enabled) {
59-
rootExtension.hermesV1Enabled.set(false)
58+
// Warn users if they still have the hermesV1Enabled property set.
59+
if (
60+
project.rootProject.hasProperty(PropertyUtils.HERMES_V1_ENABLED) ||
61+
project.rootProject.hasProperty(PropertyUtils.SCOPED_HERMES_V1_ENABLED)
62+
) {
63+
val value =
64+
(project.rootProject.findProperty(PropertyUtils.HERMES_V1_ENABLED)
65+
?: project.rootProject.findProperty(PropertyUtils.SCOPED_HERMES_V1_ENABLED))
66+
.toString()
67+
.toBoolean()
68+
if (value) {
69+
project.logger.warn(
70+
"WARNING: The 'hermesV1Enabled' property is no longer needed. Hermes V1 is now always enabled. You can safely remove this property from your gradle.properties."
71+
)
72+
} else {
73+
project.logger.warn(
74+
"WARNING: Opting out of Hermes V1 is no longer supported. The 'hermesV1Enabled=false' property will be ignored. Hermes V1 is now always enabled. Please remove this property from your gradle.properties."
75+
)
76+
}
6077
}
6178

6279
// App Only Configuration
@@ -75,8 +92,7 @@ class ReactPlugin : Plugin<Project> {
7592
File(reactNativeDir, "sdks/hermes-engine/version.properties")
7693
val versionAndGroupStrings =
7794
readVersionAndGroupStrings(project, propertiesFile, hermesVersionPropertiesFile)
78-
val hermesV1Enabled = rootExtension.hermesV1Enabled.get()
79-
configureDependencies(project, versionAndGroupStrings, hermesV1Enabled)
95+
configureDependencies(project, versionAndGroupStrings)
8096
configureRepositories(project, versionAndGroupStrings.isNightly)
8197
}
8298

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import javax.inject.Inject
1111
import org.gradle.api.Project
1212
import org.gradle.api.file.DirectoryProperty
1313
import org.gradle.api.provider.ListProperty
14-
import org.gradle.api.provider.Property
1514

1615
/**
1716
* A private extension we set on the rootProject to make easier to share values at execution time
@@ -58,6 +57,4 @@ abstract class PrivateReactExtension @Inject constructor(project: Project) {
5857

5958
val codegenDir: DirectoryProperty =
6059
objects.directoryProperty().convention(root.dir("node_modules/@react-native/codegen"))
61-
62-
val hermesV1Enabled: Property<Boolean> = objects.property(Boolean::class.java).convention(true)
6360
}

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import com.facebook.react.utils.PropertyUtils.EXCLUSIVE_ENTEPRISE_REPOSITORY
1313
import com.facebook.react.utils.PropertyUtils.INCLUDE_JITPACK_REPOSITORY
1414
import com.facebook.react.utils.PropertyUtils.INCLUDE_JITPACK_REPOSITORY_DEFAULT
1515
import com.facebook.react.utils.PropertyUtils.INTERNAL_HERMES_PUBLISHING_GROUP
16-
import com.facebook.react.utils.PropertyUtils.INTERNAL_HERMES_V1_VERSION_NAME
1716
import com.facebook.react.utils.PropertyUtils.INTERNAL_HERMES_VERSION_NAME
1817
import com.facebook.react.utils.PropertyUtils.INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO
1918
import com.facebook.react.utils.PropertyUtils.INTERNAL_REACT_PUBLISHING_GROUP
@@ -32,7 +31,6 @@ internal object DependencyUtils {
3231
internal data class Coordinates(
3332
val versionString: String,
3433
val hermesVersionString: String,
35-
val hermesV1VersionString: String,
3634
val reactGroupString: String = DEFAULT_INTERNAL_REACT_PUBLISHING_GROUP,
3735
val hermesGroupString: String = DEFAULT_INTERNAL_HERMES_PUBLISHING_GROUP,
3836
private val isHermesNightly: Boolean = false,
@@ -114,28 +112,20 @@ internal object DependencyUtils {
114112
* party libraries which are auto-linked. Specifically it takes care of:
115113
* - Forcing the react-android/hermes-android version to the one specified in the package.json
116114
* - Substituting `react-native` with `react-android` and `hermes-engine` with `hermes-android`
117-
* - Selecting between the classic Hermes and Hermes V1
118115
*/
119116
fun configureDependencies(
120117
project: Project,
121118
coordinates: Coordinates,
122-
hermesV1Enabled: Boolean = true,
123119
) {
124-
if (
125-
coordinates.versionString.isBlank() ||
126-
(!hermesV1Enabled && coordinates.hermesVersionString.isBlank()) ||
127-
(hermesV1Enabled && coordinates.hermesV1VersionString.isBlank())
128-
)
129-
return
120+
if (coordinates.versionString.isBlank() || coordinates.hermesVersionString.isBlank()) return
130121
project.rootProject.allprojects { eachProject ->
131122
eachProject.configurations.all { configuration ->
132123
// Here we set a dependencySubstitution for both react-native and hermes-engine as those
133124
// coordinates are voided due to https://github.com/facebook/react-native/issues/35210
134125
// This allows users to import libraries that are still using
135126
// implementation("com.facebook.react:react-native:+") and resolve the right dependency.
136127
configuration.resolutionStrategy.dependencySubstitution {
137-
getDependencySubstitutions(coordinates, hermesV1Enabled).forEach { (module, dest, reason)
138-
->
128+
getDependencySubstitutions(coordinates).forEach { (module, dest, reason) ->
139129
it.substitute(it.module(module)).using(it.module(dest)).because(reason)
140130
}
141131
}
@@ -146,7 +136,7 @@ internal object DependencyUtils {
146136
// Contributors only: The hermes-engine version is forced only if the user has
147137
// not opted into using nightlies for local development.
148138
configuration.resolutionStrategy.force(
149-
"${coordinates.hermesGroupString}:hermes-android:${if (hermesV1Enabled) coordinates.hermesV1VersionString else coordinates.hermesVersionString}"
139+
"${coordinates.hermesGroupString}:hermes-android:${coordinates.hermesVersionString}"
150140
)
151141
}
152142
}
@@ -155,12 +145,10 @@ internal object DependencyUtils {
155145

156146
internal fun getDependencySubstitutions(
157147
coordinates: Coordinates,
158-
hermesV1Enabled: Boolean = true,
159148
): List<Triple<String, String, String>> {
160149
val dependencySubstitution = mutableListOf<Triple<String, String, String>>()
161-
val hermesVersion =
162-
if (hermesV1Enabled) coordinates.hermesV1VersionString else coordinates.hermesVersionString
163-
val hermesVersionString = "${coordinates.hermesGroupString}:hermes-android:${hermesVersion}"
150+
val hermesVersionString =
151+
"${coordinates.hermesGroupString}:hermes-android:${coordinates.hermesVersionString}"
164152
dependencySubstitution.add(
165153
Triple(
166154
"com.facebook.react:react-native",
@@ -245,14 +233,11 @@ internal object DependencyUtils {
245233
hermesVersionString
246234
}
247235

248-
val hermesV1Version =
249-
(hermesVersionProperties[INTERNAL_HERMES_V1_VERSION_NAME] as? String).orEmpty()
250236
val isHermesNightly = (project.findProperty(INTERNAL_USE_HERMES_NIGHTLY) as? String).toBoolean()
251237

252238
return Coordinates(
253239
versionString,
254240
hermesVersion,
255-
hermesV1Version,
256241
reactGroupString,
257242
hermesGroupString,
258243
isHermesNightly,

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import com.facebook.react.utils.KotlinStdlibCompatUtils.lowercaseCompat
1313
import com.facebook.react.utils.KotlinStdlibCompatUtils.toBooleanStrictOrNullCompat
1414
import com.facebook.react.utils.PropertyUtils.EDGE_TO_EDGE_ENABLED
1515
import com.facebook.react.utils.PropertyUtils.HERMES_ENABLED
16-
import com.facebook.react.utils.PropertyUtils.HERMES_V1_ENABLED
1716
import com.facebook.react.utils.PropertyUtils.REACT_NATIVE_ARCHITECTURES
1817
import com.facebook.react.utils.PropertyUtils.SCOPED_EDGE_TO_EDGE_ENABLED
1918
import com.facebook.react.utils.PropertyUtils.SCOPED_HERMES_ENABLED
20-
import com.facebook.react.utils.PropertyUtils.SCOPED_HERMES_V1_ENABLED
2119
import com.facebook.react.utils.PropertyUtils.SCOPED_REACT_NATIVE_ARCHITECTURES
2220
import com.facebook.react.utils.PropertyUtils.SCOPED_USE_THIRD_PARTY_JSC
2321
import com.facebook.react.utils.PropertyUtils.USE_THIRD_PARTY_JSC
@@ -29,8 +27,6 @@ internal object ProjectUtils {
2927

3028
const val HERMES_FALLBACK = true
3129

32-
const val HERMES_V1_ENABLED_FALLBACK = true
33-
3430
internal fun Project.isNewArchEnabled(): Boolean = true
3531

3632
internal val Project.isHermesEnabled: Boolean
@@ -73,23 +69,6 @@ internal object ProjectUtils {
7369
(project.hasProperty(SCOPED_USE_THIRD_PARTY_JSC) &&
7470
project.property(SCOPED_USE_THIRD_PARTY_JSC).toString().toBoolean())
7571

76-
internal val Project.isHermesV1Enabled: Boolean
77-
get() =
78-
if (
79-
project.hasProperty(HERMES_V1_ENABLED) || project.hasProperty(SCOPED_HERMES_V1_ENABLED)
80-
) {
81-
(project.hasProperty(HERMES_V1_ENABLED) &&
82-
project.property(HERMES_V1_ENABLED).toString().toBoolean()) ||
83-
(project.hasProperty(SCOPED_HERMES_V1_ENABLED) &&
84-
project.property(SCOPED_HERMES_V1_ENABLED).toString().toBoolean()) ||
85-
(project.extraProperties.has(HERMES_V1_ENABLED) &&
86-
project.extraProperties.get(HERMES_V1_ENABLED).toString().toBoolean()) ||
87-
(project.extraProperties.has(SCOPED_HERMES_V1_ENABLED) &&
88-
project.extraProperties.get(SCOPED_HERMES_V1_ENABLED).toString().toBoolean())
89-
} else {
90-
HERMES_V1_ENABLED_FALLBACK
91-
}
92-
9372
internal fun Project.needsCodegenFromPackageJson(rootProperty: DirectoryProperty): Boolean {
9473
val parsedPackageJson = readPackageJsonFile(this, rootProperty)
9574
return needsCodegenFromPackageJson(parsedPackageJson)

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PropertyUtils.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ object PropertyUtils {
1818
const val HERMES_ENABLED = "hermesEnabled"
1919
const val SCOPED_HERMES_ENABLED = "react.hermesEnabled"
2020

21-
/** Public property that toggles Hermes V1 */
21+
/**
22+
* Deprecated property that used to toggle Hermes V1. Hermes V1 is now always enabled. Kept here
23+
* so we can detect usage and warn users to remove it from their gradle.properties.
24+
*/
2225
const val HERMES_V1_ENABLED = "hermesV1Enabled"
2326
const val SCOPED_HERMES_V1_ENABLED = "react.hermesV1Enabled"
2427

@@ -92,5 +95,4 @@ object PropertyUtils {
9295
* are stored in sdks/hermes-engine/version.properties
9396
*/
9497
const val INTERNAL_HERMES_VERSION_NAME = "HERMES_VERSION_NAME"
95-
const val INTERNAL_HERMES_V1_VERSION_NAME = "HERMES_V1_VERSION_NAME"
9698
}

0 commit comments

Comments
 (0)