@@ -10,15 +10,19 @@ plugins {
10
10
id(" org.jetbrains.kotlin.kapt" ) version " ${ kotlinVersion} "
11
11
}
12
12
13
+ def enableNewArchitecture = isNewArchitectureEnabled(project)
14
+ def reactNativeVersion = getPackageVersionNumber(" react-native" , rootDir)
13
15
def reactNativePath = file(findNodeModulesPath(" react-native" , rootDir))
14
16
def codegenPath = file(findNodeModulesPath(" react-native-codegen" , reactNativePath))
15
17
16
- if (isNewArchitectureEnabled(project) ) {
18
+ if (reactNativeVersion == 0 || enableNewArchitecture ) {
17
19
apply(plugin : " com.facebook.react" )
18
20
19
- react {
20
- codegenDir = codegenPath
21
- reactNativeDir = reactNativePath
21
+ if (enableNewArchitecture) {
22
+ react {
23
+ codegenDir = codegenPath
24
+ reactNativeDir = reactNativePath
25
+ }
22
26
}
23
27
}
24
28
@@ -27,8 +31,6 @@ if (isNewArchitectureEnabled(project)) {
27
31
// https://github.com/react-native-community/cli/blob/6cf12b00c02aca6d4bc843446394331d71a9749e/packages/platform-android/src/commands/runAndroid/index.ts#L180
28
32
buildDir = " ${ rootDir} /${ name} /build"
29
33
30
- def reactNativeVersion = getPackageVersionNumber(" react-native" , rootDir)
31
-
32
34
repositories {
33
35
maven {
34
36
url = uri(" ${ reactNativePath} /android" )
@@ -38,7 +40,7 @@ repositories {
38
40
google()
39
41
40
42
// TODO: Remove this block when we drop support for 0.64.
41
- if (reactNativeVersion < 6500 ) {
43
+ if (reactNativeVersion > 0 && reactNativeVersion < 6500 ) {
42
44
// Artifacts for 0.65+ are published to Maven Central. If we're on an
43
45
// older version, we still need to use JCenter.
44
46
// noinspection JcenterRepositoryObsolete
@@ -70,7 +72,7 @@ project.ext.react = [
70
72
enableFabric : isFabricEnabled(project),
71
73
enableFlipper : getFlipperVersion(rootDir),
72
74
enableHermes : true ,
73
- enableNewArchitecture : isNewArchitectureEnabled(project) ,
75
+ enableNewArchitecture : enableNewArchitecture ,
74
76
]
75
77
76
78
project. ext. signingConfigs = getSigningConfigs()
@@ -86,7 +88,7 @@ android {
86
88
87
89
// TODO: Remove this block when minSdkVersion >= 24. See
88
90
// https://stackoverflow.com/q/53402639 for details.
89
- if (reactNativeVersion < 6900 ) {
91
+ if (reactNativeVersion > 0 && reactNativeVersion < 6900 ) {
90
92
compileOptions {
91
93
sourceCompatibility(JavaVersion . VERSION_1_8 )
92
94
targetCompatibility(JavaVersion . VERSION_1_8 )
@@ -95,7 +97,7 @@ android {
95
97
96
98
kotlinOptions {
97
99
allWarningsAsErrors = true
98
- if (reactNativeVersion < 6900 ) {
100
+ if (reactNativeVersion > 0 && reactNativeVersion < 6900 ) {
99
101
jvmTarget = JavaVersion . VERSION_1_8
100
102
} else {
101
103
jvmTarget = JavaVersion . VERSION_11
@@ -129,7 +131,7 @@ android {
129
131
130
132
if (project. ext. react. enableNewArchitecture) {
131
133
externalNativeBuild {
132
- if (reactNativeVersion < 7000 ) {
134
+ if (reactNativeVersion > 0 && reactNativeVersion < 7000 ) {
133
135
ndkBuild {
134
136
arguments " APP_PLATFORM=android-${ project.ext.minSdkVersion} " ,
135
137
" APP_STL=c++_shared" ,
@@ -172,7 +174,7 @@ android {
172
174
173
175
if (project. ext. react. enableNewArchitecture) {
174
176
externalNativeBuild {
175
- if (reactNativeVersion < 7000 ) {
177
+ if (reactNativeVersion > 0 && reactNativeVersion < 7000 ) {
176
178
ndkBuild {
177
179
path " ${ projectDir} /src/main/jni/Android.mk"
178
180
}
@@ -199,7 +201,7 @@ android {
199
201
preDebugBuild. dependsOn(packageReactNdkDebugLibs)
200
202
preReleaseBuild. dependsOn(packageReactNdkReleaseLibs)
201
203
202
- if (reactNativeVersion < 7000 ) {
204
+ if (reactNativeVersion > 0 && reactNativeVersion < 7000 ) {
203
205
// Due to a bug in AGP, we have to explicitly set a dependency
204
206
// between configureNdkBuild* tasks and the preBuild tasks. This can
205
207
// be removed once this issue is resolved:
@@ -214,7 +216,7 @@ android {
214
216
dependsOn(" preReleaseBuild" )
215
217
}
216
218
}
217
- } else if (reactNativeVersion < 7100 ) {
219
+ } else if (reactNativeVersion > 0 && reactNativeVersion < 7100 ) {
218
220
// Due to a bug in AGP, we have to explicitly set a dependency
219
221
// between configureCMakeDebug* tasks and the preBuild tasks. This can
220
222
// be removed once this issue is resolved:
@@ -238,24 +240,31 @@ android {
238
240
}
239
241
}
240
242
241
- def version = getPackageVersion(" react-native" , rootDir)
242
- def allAar = file(" ${ reactNativePath} /android/com/facebook/react/react-native/${ version} /react-native-${ version} .aar" )
243
-
244
- def prepareDebugJSI = tasks. register(" prepareDebugJSI" , Copy ) {
245
- def debugAar = file(" ${ reactNativePath} /android/com/facebook/react/react-native/${ version} /react-native-${ version} -debug.aar" )
246
- from(zipTree(debugAar. exists() ? debugAar : allAar). matching({ it. include " **/libjsi.so" }))
247
- into(" ${ buildDir} /outputs/jniLibs/debug" )
248
- }
243
+ // Nightlies are downloaded from Sonatype and cannot be found under
244
+ // `node_modules`. Instead, they can be found in Gradle's cache folder,
245
+ // `.gradle/caches/modules-2/files-2.1/com.facebook.react/react-native`.
246
+ // For now, we will simply disable this step as we only need to verify
247
+ // that things build.
248
+ if (reactNativeVersion > 0 ) {
249
+ def version = getPackageVersion(" react-native" , rootDir)
250
+ def allAar = file(" ${ reactNativePath} /android/com/facebook/react/react-native/${ version} /react-native-${ version} .aar" )
251
+
252
+ def prepareDebugJSI = tasks. register(" prepareDebugJSI" , Copy ) {
253
+ def debugAar = file(" ${ reactNativePath} /android/com/facebook/react/react-native/${ version} /react-native-${ version} -debug.aar" )
254
+ from(zipTree(debugAar. exists() ? debugAar : allAar). matching({ it. include " **/libjsi.so" }))
255
+ into(" ${ buildDir} /outputs/jniLibs/debug" )
256
+ }
249
257
250
- def prepareReleaseJSI = tasks. register(" prepareReleaseJSI" , Copy ) {
251
- def releaseAar = file(" ${ reactNativePath} /android/com/facebook/react/react-native/${ version} /react-native-${ version} -release.aar" )
252
- from(zipTree(releaseAar. exists() ? releaseAar : allAar). matching({ it. include " **/libjsi.so" }))
253
- into(" ${ buildDir} /outputs/jniLibs/release" )
254
- }
258
+ def prepareReleaseJSI = tasks. register(" prepareReleaseJSI" , Copy ) {
259
+ def releaseAar = file(" ${ reactNativePath} /android/com/facebook/react/react-native/${ version} /react-native-${ version} -release.aar" )
260
+ from(zipTree(releaseAar. exists() ? releaseAar : allAar). matching({ it. include " **/libjsi.so" }))
261
+ into(" ${ buildDir} /outputs/jniLibs/release" )
262
+ }
255
263
256
- afterEvaluate {
257
- preDebugBuild. dependsOn(prepareDebugJSI)
258
- preReleaseBuild. dependsOn(prepareReleaseJSI)
264
+ afterEvaluate {
265
+ preDebugBuild. dependsOn(prepareDebugJSI)
266
+ preReleaseBuild. dependsOn(prepareReleaseJSI)
267
+ }
259
268
}
260
269
}
261
270
@@ -320,7 +329,7 @@ android {
320
329
321
330
// TODO: Remove this block when we drop support for 0.67.
322
331
// https://github.com/facebook/react-native/commit/ce74aa4ed335d4c36ce722d47937b582045e05c4
323
- if (reactNativeVersion < 6800 ) {
332
+ if (reactNativeVersion > 0 && reactNativeVersion < 6800 ) {
324
333
main. java. srcDirs + = " src/reactinstanceeventlistener-pre-0.68/java"
325
334
} else {
326
335
main. java. srcDirs + = " src/reactinstanceeventlistener-0.68/java"
@@ -341,8 +350,14 @@ dependencies {
341
350
implementation project(" :support" )
342
351
343
352
if (project. ext. react. enableHermes) {
344
- // TODO: Remove this block when we drop support for 0.68.
345
- if (reactNativeVersion < 6900 ) {
353
+ if (reactNativeVersion == 0 ) {
354
+ implementation(" com.facebook.react:hermes-engine" )
355
+ } else if (reactNativeVersion >= 6900 ) {
356
+ implementation(" com.facebook.react:hermes-engine:+" ) {
357
+ exclude(group : " com.facebook.fbjni" )
358
+ }
359
+ } else {
360
+ // TODO: Remove this block when we drop support for 0.68.
346
361
def hermesEngineDir =
347
362
findNodeModulesPath(" hermes-engine" , reactNativePath)
348
363
?: findNodeModulesPath(" hermesvm" , reactNativePath)
@@ -353,10 +368,6 @@ dependencies {
353
368
def hermesAndroidDir = " ${ hermesEngineDir} /android"
354
369
releaseImplementation files(" ${ hermesAndroidDir} /hermes-release.aar" )
355
370
debugImplementation files(" ${ hermesAndroidDir} /hermes-debug.aar" )
356
- } else {
357
- implementation(" com.facebook.react:hermes-engine:+" ) {
358
- exclude(group : " com.facebook.fbjni" )
359
- }
360
371
}
361
372
}
362
373
@@ -370,7 +381,7 @@ dependencies {
370
381
implementation libraries. kotlinStdlibJdk8
371
382
implementation libraries. kotlinReflect
372
383
373
- if (reactNativeVersion < 6800 ) {
384
+ if (reactNativeVersion > 0 && reactNativeVersion < 6800 ) {
374
385
// androidx.appcompat:appcompat:1.4.0+ breaks TextInput. This was fixed
375
386
// in react-native 0.68. For more details, see
376
387
// https://github.com/facebook/react-native/issues/31572.
0 commit comments