Skip to content

Commit 6de5afd

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Use prebuilt Hermes by default when building Android (#54707)
Summary: Changelog: [Internal] Differential Revision: D87929652
1 parent 7c603ee commit 6de5afd

File tree

6 files changed

+49
-22
lines changed

6 files changed

+49
-22
lines changed

.github/actions/build-android/action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,19 @@ runs:
4545
if [[ "${{ inputs.release-type }}" == "dry-run" ]]; then
4646
# dry-run: we only build ARM64 to save time/resources. For release/nightlies the default is to build all archs.
4747
export ORG_GRADLE_PROJECT_reactNativeArchitectures="arm64-v8a,x86" # x86 is required for E2E testing
48+
export HERMES_PREBUILT_FLAG="ORG_GRADLE_PROJECT_react.internal.useHermesNightly=true"
4849
TASKS="publishAllToMavenTempLocal build"
4950
elif [[ "${{ inputs.release-type }}" == "nightly" ]]; then
5051
# nightly: we set isSnapshot to true so artifacts are sent to the right repository on Maven Central.
5152
export ORG_GRADLE_PROJECT_isSnapshot="true"
53+
export HERMES_PREBUILT_FLAG="ORG_GRADLE_PROJECT_react.internal.useHermesNightly=true"
5254
TASKS="publishAllToMavenTempLocal publishAndroidToSonatype build"
5355
else
5456
# release: we want to build all archs (default)
57+
export HERMES_PREBUILT_FLAG="ORG_GRADLE_PROJECT_react.internal.useHermesStable=true"
5558
TASKS="publishAllToMavenTempLocal publishAndroidToSonatype build"
5659
fi
57-
./gradlew $TASKS -PenableWarningsAsErrors=true
60+
env "$HERMES_PREBUILT_FLAG" ./gradlew $TASKS -PenableWarningsAsErrors=true
5861
- name: Save Android ccache
5962
if: ${{ github.ref == 'refs/heads/main' || contains(github.ref, '-stable') }}
6063
uses: actions/cache/save@v4

build.gradle.kts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,29 @@ tasks.register("publishAllToMavenTempLocal") {
109109
tasks.register("publishAndroidToSonatype") {
110110
description = "Publish the Android artifacts to Sonatype (Maven Central or Snapshot repository)"
111111
dependsOn(":packages:react-native:ReactAndroid:publishToSonatype")
112-
dependsOn(":packages:react-native:ReactAndroid:hermes-engine:publishToSonatype")
113112
}
114113

115-
if (project.findProperty("react.internal.useHermesNightly")?.toString()?.toBoolean() == true) {
114+
var hermesSubstitution: Pair<String, String>? = null
115+
116+
if (project.findProperty("react.internal.useHermesStable")?.toString()?.toBoolean() == true) {
117+
val hermesVersions = java.util.Properties()
118+
val hermesVersionPropertiesFile =
119+
File("./packages/react-native/sdks/hermes-engine/version.properties")
120+
hermesVersionPropertiesFile.inputStream().use { hermesVersions.load(it) }
121+
val selectedHermesVersion = hermesVersions["HERMES_VERSION_NAME"] as String
122+
123+
hermesSubstitution = selectedHermesVersion to "Users opted to use stable hermes release"
124+
} else if (
125+
project.findProperty("react.internal.useHermesNightly")?.toString()?.toBoolean() == true
126+
) {
127+
hermesSubstitution = "0.+" to "Users opted to use hermes from nightly"
128+
} else {
116129
logger.warn(
117130
"""
118131
********************************************************************************
119-
INFO: You're using Hermes from nightly as you set
132+
INFO: You're building Hermes from source as you set
120133
121-
react.internal.useHermesNightly=true
134+
react.internal.useHermesNightly=false
122135
123136
in the ./gradle.properties file.
124137
@@ -127,12 +140,20 @@ if (project.findProperty("react.internal.useHermesNightly")?.toString()?.toBoole
127140
"""
128141
.trimIndent()
129142
)
143+
}
144+
145+
if (hermesSubstitution != null) {
146+
val (hermesVersion, reason) = hermesSubstitution!!
147+
project(":packages:react-native:ReactAndroid:hermes-engine") {
148+
tasks.configureEach { enabled = false }
149+
}
150+
130151
allprojects {
131152
configurations.all {
132153
resolutionStrategy.dependencySubstitution {
133154
substitute(project(":packages:react-native:ReactAndroid:hermes-engine"))
134-
.using(module("com.facebook.hermes:hermes-android:0.+"))
135-
.because("Users opted to use hermes from nightly")
155+
.using(module("com.facebook.hermes:hermes-android:$hermesVersion"))
156+
.because(reason)
136157
}
137158
}
138159
}

gradle.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ android.newDsl=false
1616
# ./gradlew <task> -PreactNativeArchitectures=x86_64
1717
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
1818

19+
# Controls whether to use Hermes from stable builds. This will force hermes version
20+
# set in the sdks/hermes-engine/version.properties file to be used. This has a higher
21+
# priotiry than react.internal.useHermesNightly.
22+
react.internal.useHermesStable=false
23+
1924
# Controls whether to use Hermes from nightly builds. This will speed up builds
2025
# but should NOT be turned on for CI or release builds.
21-
react.internal.useHermesNightly=false
26+
react.internal.useHermesNightly=true
2227

2328
# Controls whether to use Hermes 1.0. Clean and rebuild when changing.
2429
hermesV1Enabled=false

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ object PropertyUtils {
6565
*/
6666
const val INTERNAL_REACT_WINDOWS_BASH = "react.internal.windowsBashPath"
6767

68+
/**
69+
* Controls whether to use Hermes from stable builds. This will force hermes version set in the
70+
* sdks/hermes-engine/version.properties file to be used. This has a higher priotiry than
71+
* react.internal.useHermesNightly.
72+
*/
73+
const val INTERNAL_USE_HERMES_STABLE = "react.internal.useHermesStable"
74+
6875
/**
6976
* Internal property to force the build to use Hermes from the latest nightly. This speeds up the
7077
* build at the cost of not testing the latest integration against Hermes.

packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import de.undercouch.gradle.tasks.download.Download
1111
import org.apache.tools.ant.taskdefs.condition.Os
1212

1313
plugins {
14-
id("maven-publish")
1514
id("signing")
1615
alias(libs.plugins.android.library)
1716
alias(libs.plugins.download)
@@ -348,10 +347,7 @@ android {
348347
java.srcDirs("$hermesDir/lib/Platform/Intl/java", "$hermesDir/lib/Platform/Unicode/java")
349348
}
350349

351-
buildFeatures {
352-
prefab = true
353-
prefabPublishing = true
354-
}
350+
buildFeatures { prefab = true }
355351

356352
dependencies {
357353
implementation(libs.fbjni)
@@ -365,13 +361,6 @@ android {
365361
jniLibs.excludes.add("**/libfbjni.so")
366362
}
367363

368-
publishing {
369-
multipleVariants {
370-
withSourcesJar()
371-
allVariants()
372-
}
373-
}
374-
375364
prefab { create("hermesvm") { headers = prefabHeadersDir.absolutePath } }
376365
}
377366

packages/rn-tester/android/app/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@ tasks.withType<KotlinCompile>().configureEach {
179179

180180
afterEvaluate {
181181
if (
182-
project.findProperty("react.internal.useHermesNightly") == null ||
183-
project.findProperty("react.internal.useHermesNightly").toString() == "false"
182+
(project.findProperty("react.internal.useHermesNightly") == null ||
183+
project.findProperty("react.internal.useHermesNightly").toString() == "false") &&
184+
(project.findProperty("react.internal.useHermesStable") == null ||
185+
project.findProperty("react.internal.useHermesStable").toString() == "false")
184186
) {
185187
// As we're consuming Hermes from source, we want to make sure
186188
// `hermesc` is built before we actually invoke the `emit*HermesResource` task

0 commit comments

Comments
 (0)