Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,7 @@ if (project.findProperty("react.internal.useHermesStable")?.toString()?.toBoolea
)
}

val hermesV1Enabled = project.findProperty("hermesV1Enabled")?.toString()?.toBoolean() ?: true
// Hermes V1 stable releases are published without the -SNAPSHOT suffix.
// Legacy nightly builds use -SNAPSHOT.
val resolvedVersion =
if (hermesV1Enabled) hermesCompilerVersion else "$hermesCompilerVersion-SNAPSHOT"
val reason =
if (hermesV1Enabled) "Users opted to use hermes V1 stable"
else "Users opted to use hermes nightly"
hermesSubstitution = resolvedVersion to reason
hermesSubstitution = hermesCompilerVersion to "Users opted to use prebuilt hermes release"
} else {
logger.warn(
"""
Expand Down
3 changes: 0 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ react.internal.useHermesStable=false
# Controls whether to use Hermes from nightly builds. This will speed up builds
# but should NOT be turned on for CI or release builds.
react.internal.useHermesNightly=true

# Controls whether to use Hermes 1.0. Clean and rebuild when changing.
hermesV1Enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import com.facebook.react.utils.DependencyUtils.readVersionAndGroupStrings
import com.facebook.react.utils.JdkConfiguratorUtils.configureJavaToolChains
import com.facebook.react.utils.JsonUtils
import com.facebook.react.utils.NdkConfiguratorUtils.configureReactNativeNdk
import com.facebook.react.utils.ProjectUtils.isHermesV1Enabled
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
import com.facebook.react.utils.PropertyUtils
import com.facebook.react.utils.findPackageJsonFile
import java.io.File
import kotlin.system.exitProcess
Expand All @@ -55,8 +55,25 @@ class ReactPlugin : Plugin<Project> {
project,
)

if (!project.rootProject.isHermesV1Enabled) {
rootExtension.hermesV1Enabled.set(false)
// Warn users if they still have the hermesV1Enabled property set.
if (
project.rootProject.hasProperty(PropertyUtils.HERMES_V1_ENABLED) ||
project.rootProject.hasProperty(PropertyUtils.SCOPED_HERMES_V1_ENABLED)
) {
val value =
(project.rootProject.findProperty(PropertyUtils.HERMES_V1_ENABLED)
?: project.rootProject.findProperty(PropertyUtils.SCOPED_HERMES_V1_ENABLED))
.toString()
.toBoolean()
if (value) {
project.logger.warn(
"WARNING: The 'hermesV1Enabled' property is no longer needed. Hermes V1 is now always enabled. You can safely remove this property from your gradle.properties."
)
} else {
project.logger.warn(
"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."
)
}
}

// App Only Configuration
Expand All @@ -75,8 +92,7 @@ class ReactPlugin : Plugin<Project> {
File(reactNativeDir, "sdks/hermes-engine/version.properties")
val versionAndGroupStrings =
readVersionAndGroupStrings(project, propertiesFile, hermesVersionPropertiesFile)
val hermesV1Enabled = rootExtension.hermesV1Enabled.get()
configureDependencies(project, versionAndGroupStrings, hermesV1Enabled)
configureDependencies(project, versionAndGroupStrings)
configureRepositories(project, versionAndGroupStrings.isNightly)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ abstract class PrivateReactExtension @Inject constructor(project: Project) {
val codegenDir: DirectoryProperty =
objects.directoryProperty().convention(root.dir("node_modules/@react-native/codegen"))

val hermesV1Enabled: Property<Boolean> = objects.property(Boolean::class.java).convention(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,16 @@ internal object DependencyUtils {
fun configureDependencies(
project: Project,
coordinates: Coordinates,
hermesV1Enabled: Boolean = true,
) {
if (
coordinates.versionString.isBlank() ||
(!hermesV1Enabled && coordinates.hermesVersionString.isBlank()) ||
(hermesV1Enabled && coordinates.hermesV1VersionString.isBlank())
)
return
if (coordinates.versionString.isBlank() || coordinates.hermesV1VersionString.isBlank()) return
project.rootProject.allprojects { eachProject ->
eachProject.configurations.all { configuration ->
// Here we set a dependencySubstitution for both react-native and hermes-engine as those
// coordinates are voided due to https://github.com/facebook/react-native/issues/35210
// This allows users to import libraries that are still using
// implementation("com.facebook.react:react-native:+") and resolve the right dependency.
configuration.resolutionStrategy.dependencySubstitution {
getDependencySubstitutions(coordinates, hermesV1Enabled).forEach { (module, dest, reason)
->
getDependencySubstitutions(coordinates).forEach { (module, dest, reason) ->
it.substitute(it.module(module)).using(it.module(dest)).because(reason)
}
}
Expand All @@ -146,7 +139,7 @@ internal object DependencyUtils {
// Contributors only: The hermes-engine version is forced only if the user has
// not opted into using nightlies for local development.
configuration.resolutionStrategy.force(
"${coordinates.hermesGroupString}:hermes-android:${if (hermesV1Enabled) coordinates.hermesV1VersionString else coordinates.hermesVersionString}"
"${coordinates.hermesGroupString}:hermes-android:${coordinates.hermesV1VersionString}"
)
}
}
Expand All @@ -155,12 +148,10 @@ internal object DependencyUtils {

internal fun getDependencySubstitutions(
coordinates: Coordinates,
hermesV1Enabled: Boolean = true,
): List<Triple<String, String, String>> {
val dependencySubstitution = mutableListOf<Triple<String, String, String>>()
val hermesVersion =
if (hermesV1Enabled) coordinates.hermesV1VersionString else coordinates.hermesVersionString
val hermesVersionString = "${coordinates.hermesGroupString}:hermes-android:${hermesVersion}"
val hermesVersionString =
"${coordinates.hermesGroupString}:hermes-android:${coordinates.hermesV1VersionString}"
dependencySubstitution.add(
Triple(
"com.facebook.react:react-native",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import com.facebook.react.utils.KotlinStdlibCompatUtils.lowercaseCompat
import com.facebook.react.utils.KotlinStdlibCompatUtils.toBooleanStrictOrNullCompat
import com.facebook.react.utils.PropertyUtils.EDGE_TO_EDGE_ENABLED
import com.facebook.react.utils.PropertyUtils.HERMES_ENABLED
import com.facebook.react.utils.PropertyUtils.HERMES_V1_ENABLED
import com.facebook.react.utils.PropertyUtils.REACT_NATIVE_ARCHITECTURES
import com.facebook.react.utils.PropertyUtils.SCOPED_EDGE_TO_EDGE_ENABLED
import com.facebook.react.utils.PropertyUtils.SCOPED_HERMES_ENABLED
import com.facebook.react.utils.PropertyUtils.SCOPED_HERMES_V1_ENABLED
import com.facebook.react.utils.PropertyUtils.SCOPED_REACT_NATIVE_ARCHITECTURES
import com.facebook.react.utils.PropertyUtils.SCOPED_USE_THIRD_PARTY_JSC
import com.facebook.react.utils.PropertyUtils.USE_THIRD_PARTY_JSC
Expand All @@ -29,7 +27,6 @@ internal object ProjectUtils {

const val HERMES_FALLBACK = true

const val HERMES_V1_ENABLED_FALLBACK = true

internal fun Project.isNewArchEnabled(): Boolean = true

Expand Down Expand Up @@ -73,23 +70,6 @@ internal object ProjectUtils {
(project.hasProperty(SCOPED_USE_THIRD_PARTY_JSC) &&
project.property(SCOPED_USE_THIRD_PARTY_JSC).toString().toBoolean())

internal val Project.isHermesV1Enabled: Boolean
get() =
if (
project.hasProperty(HERMES_V1_ENABLED) || project.hasProperty(SCOPED_HERMES_V1_ENABLED)
) {
(project.hasProperty(HERMES_V1_ENABLED) &&
project.property(HERMES_V1_ENABLED).toString().toBoolean()) ||
(project.hasProperty(SCOPED_HERMES_V1_ENABLED) &&
project.property(SCOPED_HERMES_V1_ENABLED).toString().toBoolean()) ||
(project.extraProperties.has(HERMES_V1_ENABLED) &&
project.extraProperties.get(HERMES_V1_ENABLED).toString().toBoolean()) ||
(project.extraProperties.has(SCOPED_HERMES_V1_ENABLED) &&
project.extraProperties.get(SCOPED_HERMES_V1_ENABLED).toString().toBoolean())
} else {
HERMES_V1_ENABLED_FALLBACK
}

internal fun Project.needsCodegenFromPackageJson(rootProperty: DirectoryProperty): Boolean {
val parsedPackageJson = readPackageJsonFile(this, rootProperty)
return needsCodegenFromPackageJson(parsedPackageJson)
Expand Down
Loading
Loading