Skip to content

Commit 813b944

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Read Hermes V1 opt-in flag from the app's properties (#53665)
Summary: Pull Request resolved: #53665 Changelog: [ANDROID][FIXED] - Read the Hermes V1 opt-in flag from the apps properties when building from source Reviewed By: cortinico Differential Revision: D82018545 fbshipit-source-id: f3c6fdbac190f47b6bf6836105d9e0909d8b86ba
1 parent cf5040b commit 813b944

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.facebook.react.utils.PropertyUtils.SCOPED_USE_THIRD_PARTY_JSC
2323
import com.facebook.react.utils.PropertyUtils.USE_THIRD_PARTY_JSC
2424
import org.gradle.api.Project
2525
import org.gradle.api.file.DirectoryProperty
26+
import org.jetbrains.kotlin.gradle.plugin.extraProperties
2627

2728
internal object ProjectUtils {
2829

@@ -75,7 +76,11 @@ internal object ProjectUtils {
7576
(project.hasProperty(HERMES_V1_ENABLED) &&
7677
project.property(HERMES_V1_ENABLED).toString().toBoolean()) ||
7778
(project.hasProperty(SCOPED_HERMES_V1_ENABLED) &&
78-
project.property(SCOPED_HERMES_V1_ENABLED).toString().toBoolean())
79+
project.property(SCOPED_HERMES_V1_ENABLED).toString().toBoolean()) ||
80+
(project.extraProperties.has(HERMES_V1_ENABLED) &&
81+
project.extraProperties.get(HERMES_V1_ENABLED).toString().toBoolean()) ||
82+
(project.extraProperties.has(SCOPED_HERMES_V1_ENABLED) &&
83+
project.extraProperties.get(SCOPED_HERMES_V1_ENABLED).toString().toBoolean())
7984

8085
internal fun Project.needsCodegenFromPackageJson(rootProperty: DirectoryProperty): Boolean {
8186
val parsedPackageJson = readPackageJsonFile(this, rootProperty)

settings.gradle.kts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,26 @@ configure<com.facebook.react.ReactSettingsExtension> {
4444
lockFiles = files("yarn.lock"),
4545
)
4646
}
47+
48+
// Gradle properties defined in `gradle.properties` are not inherited by
49+
// included builds, see https://github.com/gradle/gradle/issues/2534.
50+
// This is a workaround to read the configuration from the consuming project,
51+
// and apply relevant properties to the :react-native project.
52+
buildscript {
53+
val properties = java.util.Properties()
54+
val propertiesToInherit = listOf("hermesV1Enabled", "react.hermesV1Enabled")
55+
56+
try {
57+
file("../../android/gradle.properties").inputStream().use { properties.load(it) }
58+
59+
gradle.rootProject {
60+
propertiesToInherit.forEach { property ->
61+
if (properties.containsKey(property)) {
62+
gradle.rootProject.extra.set(property, properties.getProperty(property))
63+
}
64+
}
65+
}
66+
} catch (e: Exception) {
67+
// fail silently
68+
}
69+
}

0 commit comments

Comments
 (0)