1
1
apply plugin : " com.android.application"
2
2
3
3
import com.android.build.OutputFile
4
+ import org.apache.tools.ant.taskdefs.condition.Os
4
5
5
6
/**
6
7
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
@@ -78,7 +79,7 @@ import com.android.build.OutputFile
78
79
*/
79
80
80
81
project. ext. react = [
81
- enableHermes : false , // clean and rebuild if changing
82
+ enableHermes : true , // clean and rebuild if changing
82
83
]
83
84
84
85
apply from : " ../../node_modules/react-native/react.gradle"
@@ -142,21 +143,19 @@ android {
142
143
buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
143
144
144
145
if (isNewArchitectureEnabled()) {
145
- // 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.
146
147
externalNativeBuild {
147
- ndkBuild {
148
- arguments " APP_PLATFORM=android-21" ,
149
- " APP_STL=c++_shared" ,
150
- " NDK_TOOLCHAIN_VERSION=clang" ,
151
- " GENERATED_SRC_DIR=$buildDir /generated/source" ,
152
- " PROJECT_BUILD_DIR=$buildDir " ,
153
- " REACT_ANDROID_DIR=$rootDir /../node_modules/react-native/ReactAndroid" ,
154
- " REACT_ANDROID_BUILD_DIR=$rootDir /../node_modules/react-native/ReactAndroid/build"
155
- cFlags " -Wall" , " -Werror" , " -fexceptions" , " -frtti" , " -DWITH_INSPECTOR=1"
156
- cppFlags " -std=c++17"
157
- // Make sure this target name is the same you specify inside the
158
- // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
159
- targets " example_appmodules"
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"
154
+ }
155
+ }
156
+ if (! enableSeparateBuildPerCPUArchitecture) {
157
+ ndk {
158
+ abiFilters (* reactNativeArchitectures())
160
159
}
161
160
}
162
161
}
@@ -165,8 +164,8 @@ android {
165
164
if (isNewArchitectureEnabled()) {
166
165
// We configure the NDK build only if you decide to opt-in for the New Architecture.
167
166
externalNativeBuild {
168
- ndkBuild {
169
- path " $projectDir /src/main/jni/Android.mk "
167
+ cmake {
168
+ path " $projectDir /src/main/jni/CMakeLists.txt "
170
169
}
171
170
}
172
171
def reactAndroidProjectDir = project(' :ReactAndroid' ). projectDir
@@ -186,6 +185,20 @@ android {
186
185
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
187
186
preDebugBuild. dependsOn(packageReactNdkDebugLibs)
188
187
preReleaseBuild. dependsOn(packageReactNdkReleaseLibs)
188
+
189
+ // Due to a bug inside AGP, we have to explicitly set a dependency
190
+ // between configureCMakeDebug* tasks and the preBuild tasks.
191
+ // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
192
+ configureCMakeRelWithDebInfo. dependsOn(preReleaseBuild)
193
+ configureCMakeDebug. dependsOn(preDebugBuild)
194
+ reactNativeArchitectures(). each { architecture ->
195
+ tasks. findByName(" configureCMakeDebug[${ architecture} ]" )?. configure {
196
+ dependsOn(" preDebugBuild" )
197
+ }
198
+ tasks. findByName(" configureCMakeRelWithDebInfo[${ architecture} ]" )?. configure {
199
+ dependsOn(" preReleaseBuild" )
200
+ }
201
+ }
189
202
}
190
203
}
191
204
@@ -238,14 +251,8 @@ android {
238
251
dependencies {
239
252
implementation fileTree(dir : " libs" , include : [" *.jar" ])
240
253
241
- // If new architecture is enabled, we let you build RN from source
242
- // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
243
- if (isNewArchitectureEnabled()) {
244
- implementation project(" :ReactAndroid" )
245
- } else {
246
- // noinspection GradleDynamicVersion
247
- implementation " com.facebook.react:react-native:+" // From node_modules
248
- }
254
+ // noinspection GradleDynamicVersion
255
+ implementation " com.facebook.react:react-native:+" // From node_modules
249
256
250
257
implementation " androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
251
258
@@ -263,14 +270,31 @@ dependencies {
263
270
}
264
271
265
272
if (enableHermes) {
266
- def hermesPath = " ../../node_modules/hermes-engine/android/" ;
267
- debugImplementation files(hermesPath + " hermes-debug.aar" )
268
- 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
+ }
269
277
} else {
270
278
implementation jscFlavor
271
279
}
272
280
}
273
281
282
+ if (isNewArchitectureEnabled()) {
283
+ // If new architecture is enabled, we let you build RN from source
284
+ // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
285
+ // This will be applied to all the imported transtitive dependency.
286
+ configurations. all {
287
+ resolutionStrategy. dependencySubstitution {
288
+ substitute(module(" com.facebook.react:react-native" ))
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" )
294
+ }
295
+ }
296
+ }
297
+
274
298
// Run this once to be able to run the application with BUCK
275
299
// puts all compile dependencies into folder libs for BUCK to use
276
300
task copyDownloadableDepsToLibs (type : Copy ) {
0 commit comments