@@ -121,16 +121,19 @@ def jscFlavor = 'org.webkit:android-jsc:+'
121
121
/**
122
122
* Whether to enable the Hermes VM.
123
123
*
124
- * This should be set on project.ext.react and mirrored here. If it is not set
124
+ * This should be set on project.ext.react and that value will be read here. If it is not set
125
125
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
126
126
* and the benefits of using Hermes will therefore be sharply reduced.
127
127
*/
128
128
def enableHermes = project. ext. react. get(" enableHermes" , false );
129
129
130
130
/**
131
- * Required in order to build native code for debug builds
131
+ * Architectures to build native code for.
132
132
*/
133
- def nativeArchitectures = project. getProperties(). get(" reactNativeDebugArchitectures" )
133
+ def reactNativeArchitectures () {
134
+ def value = project. getProperties(). get(" reactNativeArchitectures" )
135
+ return value ? value. split(" ," ) : [" armeabi-v7a" , " x86" , " x86_64" , " arm64-v8a" ]
136
+ }
134
137
135
138
android {
136
139
compileSdkVersion rootProject. ext. compileSdkVersion
@@ -154,13 +157,81 @@ android {
154
157
multiDexEnabled rootProject. ext. multiDexEnabled
155
158
versionCode 1001018803
156
159
versionName " 1.1.88-3"
160
+ buildConfigField " boolean" , " IS_NEW_ARCHITECTURE_ENABLED" , isNewArchitectureEnabled(). toString()
161
+
162
+ if (isNewArchitectureEnabled()) {
163
+ // We configure the NDK build only if you decide to opt-in for the New Architecture.
164
+ externalNativeBuild {
165
+ ndkBuild {
166
+ arguments " APP_PLATFORM=android-21" ,
167
+ " APP_STL=c++_shared" ,
168
+ " NDK_TOOLCHAIN_VERSION=clang" ,
169
+ " GENERATED_SRC_DIR=$buildDir /generated/source" ,
170
+ " PROJECT_BUILD_DIR=$buildDir " ,
171
+ " REACT_ANDROID_DIR=$rootDir /../node_modules/react-native/ReactAndroid" ,
172
+ " REACT_ANDROID_BUILD_DIR=$rootDir /../node_modules/react-native/ReactAndroid/build" ,
173
+ " NODE_MODULES_DIR=$rootDir /../node_modules"
174
+ cFlags " -Wall" , " -Werror" , " -fexceptions" , " -frtti" , " -DWITH_INSPECTOR=1"
175
+ cppFlags " -std=c++17"
176
+ // Make sure this target name is the same you specify inside the
177
+ // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
178
+ targets " rndiffapp_appmodules"
179
+ }
180
+ }
181
+ if (! enableSeparateBuildPerCPUArchitecture) {
182
+ ndk {
183
+ abiFilters (* reactNativeArchitectures())
184
+ }
185
+ }
186
+ }
157
187
}
188
+
189
+ if (isNewArchitectureEnabled()) {
190
+ // We configure the NDK build only if you decide to opt-in for the New Architecture.
191
+ externalNativeBuild {
192
+ ndkBuild {
193
+ path " $projectDir /src/main/jni/Android.mk"
194
+ }
195
+ }
196
+ def reactAndroidProjectDir = project(' :ReactAndroid' ). projectDir
197
+ def packageReactNdkDebugLibs = tasks. register(" packageReactNdkDebugLibs" , Copy ) {
198
+ dependsOn(" :ReactAndroid:packageReactNdkDebugLibsForBuck" )
199
+ from(" $reactAndroidProjectDir /src/main/jni/prebuilt/lib" )
200
+ into(" $buildDir /react-ndk/exported" )
201
+ }
202
+ def packageReactNdkReleaseLibs = tasks. register(" packageReactNdkReleaseLibs" , Copy ) {
203
+ dependsOn(" :ReactAndroid:packageReactNdkReleaseLibsForBuck" )
204
+ from(" $reactAndroidProjectDir /src/main/jni/prebuilt/lib" )
205
+ into(" $buildDir /react-ndk/exported" )
206
+ }
207
+ afterEvaluate {
208
+ // If you wish to add a custom TurboModule or component locally,
209
+ // you should uncomment this line.
210
+ // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
211
+ preDebugBuild. dependsOn(packageReactNdkDebugLibs)
212
+ preReleaseBuild. dependsOn(packageReactNdkReleaseLibs)
213
+ // Due to a bug inside AGP, we have to explicitly set a dependency
214
+ // between configureNdkBuild* tasks and the preBuild tasks.
215
+ // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
216
+ configureNdkBuildRelease. dependsOn(preReleaseBuild)
217
+ configureNdkBuildDebug. dependsOn(preDebugBuild)
218
+ reactNativeArchitectures(). each { architecture ->
219
+ tasks. findByName(" configureNdkBuildDebug[${ architecture} ]" )?. configure {
220
+ dependsOn(" preDebugBuild" )
221
+ }
222
+ tasks. findByName(" configureNdkBuildRelease[${ architecture} ]" )?. configure {
223
+ dependsOn(" preReleaseBuild" )
224
+ }
225
+ }
226
+ }
227
+ }
228
+
158
229
splits {
159
230
abi {
160
231
reset()
161
232
enable enableSeparateBuildPerCPUArchitecture
162
233
universalApk false // If true, also generate a universal APK
163
- include " armeabi-v7a " , " x86 " , " arm64-v8a " , " x86_64 "
234
+ include ( * reactNativeArchitectures())
164
235
}
165
236
}
166
237
signingConfigs {
@@ -182,11 +253,6 @@ android {
182
253
buildTypes {
183
254
debug {
184
255
signingConfig signingConfigs. debug
185
- if (nativeArchitectures) {
186
- ndk {
187
- abiFilters nativeArchitectures. split(' ,' )
188
- }
189
- }
190
256
}
191
257
release {
192
258
signingConfig signingConfigs. release
@@ -213,6 +279,7 @@ android {
213
279
214
280
dependencies {
215
281
implementation fileTree(dir : " libs" , include : [" *.jar" ])
282
+
216
283
// noinspection GradleDynamicVersion
217
284
implementation " com.facebook.react:react-native:+" // From node_modules
218
285
@@ -232,9 +299,10 @@ dependencies {
232
299
}
233
300
234
301
if (enableHermes) {
235
- def hermesPath = " ../../node_modules/hermes-engine/android/" ;
236
- debugImplementation files(hermesPath + " hermes-debug.aar" )
237
- releaseImplementation files(hermesPath + " hermes-release.aar" )
302
+ // noinspection GradleDynamicVersion
303
+ implementation(" com.facebook.react:hermes-engine:+" ) { // From node_modules
304
+ exclude group :' com.facebook.fbjni'
305
+ }
238
306
} else {
239
307
implementation jscFlavor
240
308
}
@@ -260,6 +328,22 @@ dependencies {
260
328
implementation " com.squareup.okhttp3:okhttp-urlconnection:4.+"
261
329
}
262
330
331
+ if (isNewArchitectureEnabled()) {
332
+ // If new architecture is enabled, we let you build RN from source
333
+ // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
334
+ // This will be applied to all the imported transtitive dependency.
335
+ configurations. all {
336
+ resolutionStrategy. dependencySubstitution {
337
+ substitute(module(" com.facebook.react:react-native" ))
338
+ .using(project(" :ReactAndroid" ))
339
+ .because(" On New Architecture we're building React Native from source" )
340
+ substitute(module(" com.facebook.react:hermes-engine" ))
341
+ .using(project(" :ReactAndroid:hermes-engine" ))
342
+ .because(" On New Architecture we're building Hermes from source" )
343
+ }
344
+ }
345
+ }
346
+
263
347
// Run this once to be able to run the application with BUCK
264
348
// puts all compile dependencies into folder libs for BUCK to use
265
349
task copyDownloadableDepsToLibs (type : Copy ) {
@@ -274,4 +358,11 @@ if (googleServicesFile.exists()) {
274
358
}
275
359
apply plugin : ' com.google.firebase.crashlytics'
276
360
361
+ def isNewArchitectureEnabled () {
362
+ // To opt-in for the New Architecture, you can either:
363
+ // - Set `newArchEnabled` to true inside the `gradle.properties` file
364
+ // - Invoke gradle with `-newArchEnabled=true`
365
+ // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
366
+ return project. hasProperty(" newArchEnabled" ) && project. newArchEnabled == " true"
367
+ }
277
368
0 commit comments