@@ -75,7 +75,7 @@ set(CMAKE_VERBOSE_MAKEFILE on)
75
75
76
76
{{ libraryIncludes }}
77
77
78
- set(AUTOLINKED_LIBRARIES
78
+ set(AUTOLINKED_LIBRARIES
79
79
{{ libraryModules }}
80
80
)
81
81
"""
@@ -143,18 +143,20 @@ class ReactNativeModules {
143
143
private ArrayList<HashMap<String , String > > reactNativeModules
144
144
private ArrayList<String > unstable_reactLegacyComponentNames
145
145
private HashMap<String , ArrayList > reactNativeModulesBuildVariants
146
+ private String reactNativeVersion
146
147
147
148
private static String LOG_PREFIX = " :ReactNative:"
148
149
149
150
ReactNativeModules (Logger logger , File root ) {
150
151
this . logger = logger
151
152
this . root = root
152
153
153
- def (nativeModules, reactNativeModulesBuildVariants, androidProject) = this . getReactNativeConfig()
154
+ def (nativeModules, reactNativeModulesBuildVariants, androidProject, reactNativeVersion ) = this . getReactNativeConfig()
154
155
this . reactNativeModules = nativeModules
155
156
this . reactNativeModulesBuildVariants = reactNativeModulesBuildVariants
156
157
this . packageName = androidProject[" packageName" ]
157
158
this . unstable_reactLegacyComponentNames = androidProject[" unstable_reactLegacyComponentNames" ]
159
+ this . reactNativeVersion = reactNativeVersion
158
160
}
159
161
160
162
/**
@@ -180,7 +182,7 @@ class ReactNativeModules {
180
182
if (reactNativeModulesBuildVariants. containsKey(nameCleansed)) {
181
183
reactNativeModulesBuildVariants
182
184
.get(nameCleansed)
183
- .forEach { buildVariant ->
185
+ .forEach { buildVariant ->
184
186
if (dependencyConfiguration != null ) {
185
187
" ${ buildVariant}${ dependencyConfiguration} "
186
188
} else {
@@ -218,7 +220,7 @@ class ReactNativeModules {
218
220
// Before adding the package replacement mechanism,
219
221
// BuildConfig and R classes were imported automatically
220
222
// into the scope of the file. We want to replace all
221
- // non-FQDN references to those classes with the package name
223
+ // non-FQDN references to those classes with the package name
222
224
// of the MainApplication.
223
225
//
224
226
// We want to match "R" or "BuildConfig":
@@ -324,7 +326,7 @@ class ReactNativeModules {
324
326
result + = it. componentDescriptors. collect {
325
327
" providerRegistry->add(concreteComponentDescriptorProvider<${ it} >());"
326
328
}. join(' \n ' )
327
- }
329
+ }
328
330
result
329
331
}. join(" \n " )
330
332
}
@@ -403,7 +405,7 @@ class ReactNativeModules {
403
405
404
406
ArrayList<HashMap<String , String > > reactNativeModules = new ArrayList<HashMap<String , String > > ()
405
407
HashMap<String , ArrayList > reactNativeModulesBuildVariants = new HashMap<String , ArrayList > ()
406
-
408
+
407
409
/**
408
410
* Resolve the CLI location from Gradle file
409
411
*
@@ -427,6 +429,7 @@ class ReactNativeModules {
427
429
}
428
430
def dependencies = json[" dependencies" ]
429
431
def project = json[" project" ][" android" ]
432
+ def reactNativeVersion = json[" version" ]
430
433
431
434
if (project == null ) {
432
435
throw new Exception (" React Native CLI failed to determine Android project configuration. This is likely due to misconfiguration. Config output:\n ${ json.toMapString()} " )
@@ -440,7 +443,7 @@ class ReactNativeModules {
440
443
441
444
if (androidConfig != null && androidConfig[" sourceDir" ] != null ) {
442
445
this . logger. info(" ${ LOG_PREFIX} Automatically adding native module '${ name} '" )
443
-
446
+
444
447
HashMap reactNativeModuleConfig = new HashMap<String , String > ()
445
448
def nameCleansed = name. replaceAll(' [~*!\' ()]+' , ' _' ). replaceAll(' ^@([\\ w-.]+)/' , ' $1_' )
446
449
reactNativeModuleConfig. put(" name" , name)
@@ -465,14 +468,14 @@ class ReactNativeModules {
465
468
}
466
469
467
470
this . logger. trace(" ${ LOG_PREFIX} '${ name} ': ${ reactNativeModuleConfig.toMapString()} " )
468
-
471
+
469
472
reactNativeModules. add(reactNativeModuleConfig)
470
473
} else {
471
474
this . logger. info(" ${ LOG_PREFIX} Skipping native module '${ name} '" )
472
475
}
473
476
}
474
477
475
- return [reactNativeModules, reactNativeModulesBuildVariants, json[" project" ][" android" ]];
478
+ return [reactNativeModules, reactNativeModulesBuildVariants, json[" project" ][" android" ], reactNativeVersion ];
476
479
}
477
480
}
478
481
@@ -485,6 +488,21 @@ def projectRoot = rootProject.projectDir
485
488
486
489
def autoModules = new ReactNativeModules (logger, projectRoot)
487
490
491
+ def reactNativeVersionRequireNewArchEnabled (autoModules ) {
492
+ def rnVersion = autoModules. reactNativeVersion
493
+ def regexPattern = / ^(\d +)\. (\d +)\. (\d +)(?:-(\w +(?:[-.]\d +)?))?$/
494
+
495
+ if (rnVersion =~ regexPattern) {
496
+ def result = (rnVersion =~ regexPattern). findAll(). first()
497
+
498
+ def major = result[1 ]. toInteger()
499
+ if (major > 0 && major < 1000 ) {
500
+ return true
501
+ }
502
+ }
503
+ return false
504
+ }
505
+
488
506
/* * -----------------------
489
507
* Exported Extensions
490
508
* ------------------------ */
@@ -516,15 +534,16 @@ ext.applyNativeModulesAppBuildGradle = { Project project, String root = null ->
516
534
517
535
task generateNewArchitectureFiles {
518
536
doLast {
519
- autoModules. generateCmakeFile(generatedJniDir, " Android-rncli.cmake" , cmakeTemplate)
537
+ autoModules. generateCmakeFile(generatedJniDir, " Android-rncli.cmake" , cmakeTemplate)
520
538
autoModules. generateRncliCpp(generatedJniDir, " rncli.cpp" , rncliCppTemplate)
521
539
autoModules. generateRncliH(generatedJniDir, " rncli.h" , rncliHTemplate)
522
540
}
523
541
}
524
542
525
543
preBuild. dependsOn generatePackageList
526
-
527
- if (project. hasProperty(" newArchEnabled" ) && project. newArchEnabled == " true" ) {
544
+ def isNewArchEnabled = (project. hasProperty(" newArchEnabled" ) && project. newArchEnabled == " true" ) ||
545
+ reactNativeVersionRequireNewArchEnabled(autoModules)
546
+ if (isNewArchEnabled) {
528
547
preBuild. dependsOn generateNewArchitectureFiles
529
548
}
530
549
0 commit comments