@@ -79,7 +79,7 @@ import org.apache.tools.ant.taskdefs.condition.Os
7979 */
8080
8181project. ext. react = [
82- enableHermes : false , // clean and rebuild if changing
82+ enableHermes : true , // clean and rebuild if changing
8383]
8484
8585apply from : " ../../node_modules/react-native/react.gradle"
@@ -143,25 +143,14 @@ android {
143143 buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
144144
145145 if (isNewArchitectureEnabled()) {
146- // We configure the NDK build only if you decide to opt-in for the New Architecture.
146+ // We configure the CMake build only if you decide to opt-in for the New Architecture.
147147 externalNativeBuild {
148- ndkBuild {
149- arguments " APP_PLATFORM=android-21" ,
150- " APP_STL=c++_shared" ,
151- " NDK_TOOLCHAIN_VERSION=clang" ,
152- " GENERATED_SRC_DIR=$buildDir /generated/source" ,
153- " PROJECT_BUILD_DIR=$buildDir " ,
154- " REACT_ANDROID_DIR=$rootDir /../node_modules/react-native/ReactAndroid" ,
155- " REACT_ANDROID_BUILD_DIR=$rootDir /../node_modules/react-native/ReactAndroid/build"
156- cFlags " -Wall" , " -Werror" , " -fexceptions" , " -frtti" , " -DWITH_INSPECTOR=1"
157- cppFlags " -std=c++17"
158- // Make sure this target name is the same you specify inside the
159- // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
160- targets " projectname_appmodules"
161- // Fix for windows limit on number of character in file paths and in command lines
162- if (Os . isFamily(Os . FAMILY_WINDOWS )) {
163- arguments " NDK_APP_SHORT_COMMANDS=true"
164- }
148+ cmake {
149+ arguments " -DPROJECT_BUILD_DIR=$buildDir " ,
150+ " -DREACT_ANDROID_DIR=$rootDir /../node_modules/react-native/ReactAndroid" ,
151+ " -DREACT_ANDROID_BUILD_DIR=$rootDir /../node_modules/react-native/ReactAndroid/build" ,
152+ " -DNODE_MODULES_DIR=$rootDir /../node_modules" ,
153+ " -DANDROID_STL=c++_shared"
165154 }
166155 }
167156 if (! enableSeparateBuildPerCPUArchitecture) {
@@ -175,8 +164,8 @@ android {
175164 if (isNewArchitectureEnabled()) {
176165 // We configure the NDK build only if you decide to opt-in for the New Architecture.
177166 externalNativeBuild {
178- ndkBuild {
179- path " $projectDir /src/main/jni/Android.mk "
167+ cmake {
168+ path " $projectDir /src/main/jni/CMakeLists.txt "
180169 }
181170 }
182171 def reactAndroidProjectDir = project(' :ReactAndroid' ). projectDir
@@ -198,15 +187,15 @@ android {
198187 preReleaseBuild. dependsOn(packageReactNdkReleaseLibs)
199188
200189 // Due to a bug inside AGP, we have to explicitly set a dependency
201- // between configureNdkBuild * tasks and the preBuild tasks.
190+ // between configureCMakeDebug * tasks and the preBuild tasks.
202191 // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
203- configureNdkBuildRelease . dependsOn(preReleaseBuild)
204- configureNdkBuildDebug . dependsOn(preDebugBuild)
192+ configureCMakeRelWithDebInfo . dependsOn(preReleaseBuild)
193+ configureCMakeDebug . dependsOn(preDebugBuild)
205194 reactNativeArchitectures(). each { architecture ->
206- tasks. findByName(" configureNdkBuildDebug [${ architecture} ]" )?. configure {
195+ tasks. findByName(" configureCMakeDebug [${ architecture} ]" )?. configure {
207196 dependsOn(" preDebugBuild" )
208197 }
209- tasks. findByName(" configureNdkBuildRelease [${ architecture} ]" )?. configure {
198+ tasks. findByName(" configureCMakeRelWithDebInfo [${ architecture} ]" )?. configure {
210199 dependsOn(" preReleaseBuild" )
211200 }
212201 }
@@ -281,9 +270,10 @@ dependencies {
281270 }
282271
283272 if (enableHermes) {
284- def hermesPath = " ../../node_modules/hermes-engine/android/" ;
285- debugImplementation files(hermesPath + " hermes-debug.aar" )
286- releaseImplementation files(hermesPath + " hermes-release.aar" )
273+ // noinspection GradleDynamicVersion
274+ implementation(" com.facebook.react:hermes-engine:+" ) { // From node_modules
275+ exclude group :' com.facebook.fbjni'
276+ }
287277 } else {
288278 implementation jscFlavor
289279 }
@@ -296,7 +286,11 @@ if (isNewArchitectureEnabled()) {
296286 configurations. all {
297287 resolutionStrategy. dependencySubstitution {
298288 substitute(module(" com.facebook.react:react-native" ))
299- .using(project(" :ReactAndroid" )). because(" On New Architecture we're building React Native from source" )
289+ .using(project(" :ReactAndroid" ))
290+ .because(" On New Architecture we're building React Native from source" )
291+ substitute(module(" com.facebook.react:hermes-engine" ))
292+ .using(project(" :ReactAndroid:hermes-engine" ))
293+ .because(" On New Architecture we're building Hermes from source" )
300294 }
301295 }
302296}
0 commit comments