@@ -76,7 +76,8 @@ import com.android.build.OutputFile
7676 */
7777
7878project. ext. react = [
79- entryFile : " index.js"
79+ entryFile : " index.js" ,
80+ enableHermes : false , // clean and rebuild if changing
8081]
8182
8283apply from : " ../../node_modules/react-native/react.gradle"
@@ -97,13 +98,26 @@ def enableSeparateBuildPerCPUArchitecture = false
9798def enableProguardInReleaseBuilds = false
9899
99100/**
100- * Use international variant JavaScriptCore
101- * International variant includes ICU i18n library and necessary data allowing to use
102- * e.g. Date.toLocaleString and String.localeCompare that give correct results
103- * when using with locales other than en-US.
104- * Note that this variant is about 6MiB larger per architecture than default.
101+ * The preferred build flavor of JavaScriptCore.
102+ *
103+ * For example, to use the international variant, you can use:
104+ * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
105+ *
106+ * The international variant includes ICU i18n library and necessary data
107+ * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
108+ * give correct results when using with locales other than en-US. Note that
109+ * this variant is about 6MiB larger per architecture than default.
105110 */
106- def useIntlJsc = false
111+ def jscFlavor = ' org.webkit:android-jsc:+'
112+
113+ /**
114+ * Whether to enable the Hermes VM.
115+ *
116+ * This should be set on project.ext.react and mirrored here. If it is not set
117+ * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
118+ * and the benefits of using Hermes will therefore be sharply reduced.
119+ */
120+ def enableHermes = project. ext. react. get(" enableHermes" , false );
107121
108122android {
109123 compileSdkVersion rootProject. ext. compileSdkVersion
@@ -159,19 +173,30 @@ android {
159173 output. versionCodeOverride =
160174 versionCodes. get(abi) * 1048576 + defaultConfig. versionCode
161175 }
176+
162177 }
163178 }
179+
180+ packagingOptions {
181+ pickFirst ' **/armeabi-v7a/libc++_shared.so'
182+ pickFirst ' **/x86/libc++_shared.so'
183+ pickFirst ' **/arm64-v8a/libc++_shared.so'
184+ pickFirst ' **/x86_64/libc++_shared.so'
185+ pickFirst ' **/x86/libjsc.so'
186+ pickFirst ' **/armeabi-v7a/libjsc.so'
187+ }
164188}
165189
166190dependencies {
167191 implementation fileTree(dir : " libs" , include : [" *.jar" ])
168192 implementation " com.facebook.react:react-native:+" // From node_modules
169193
170- // JSC from node_modules
171- if (useIntlJsc) {
172- implementation ' org.webkit:android-jsc-intl:+'
194+ if (enableHermes) {
195+ def hermesPath = " ../../node_modules/hermesvm/android/" ;
196+ debugImplementation files(hermesPath + " hermes-debug.aar" )
197+ releaseImplementation files(hermesPath + " hermes-release.aar" )
173198 } else {
174- implementation ' org.webkit:android-jsc:+ '
199+ implementation jscFlavor
175200 }
176201}
177202
0 commit comments