@@ -10,15 +10,19 @@ plugins {
1010 id(" org.jetbrains.kotlin.kapt" ) version " ${ kotlinVersion} "
1111}
1212
13+ def enableNewArchitecture = isNewArchitectureEnabled(project)
14+ def reactNativeVersion = getPackageVersionNumber(" react-native" , rootDir)
1315def reactNativePath = file(findNodeModulesPath(" react-native" , rootDir))
1416def codegenPath = file(findNodeModulesPath(" react-native-codegen" , reactNativePath))
1517
16- if (isNewArchitectureEnabled(project) ) {
18+ if (reactNativeVersion == 0 || enableNewArchitecture ) {
1719 apply(plugin : " com.facebook.react" )
1820
19- react {
20- codegenDir = codegenPath
21- reactNativeDir = reactNativePath
21+ if (enableNewArchitecture) {
22+ react {
23+ codegenDir = codegenPath
24+ reactNativeDir = reactNativePath
25+ }
2226 }
2327}
2428
@@ -27,8 +31,6 @@ if (isNewArchitectureEnabled(project)) {
2731// https://github.com/react-native-community/cli/blob/6cf12b00c02aca6d4bc843446394331d71a9749e/packages/platform-android/src/commands/runAndroid/index.ts#L180
2832buildDir = " ${ rootDir} /${ name} /build"
2933
30- def reactNativeVersion = getPackageVersionNumber(" react-native" , rootDir)
31-
3234repositories {
3335 maven {
3436 url = uri(" ${ reactNativePath} /android" )
@@ -38,7 +40,7 @@ repositories {
3840 google()
3941
4042 // TODO: Remove this block when we drop support for 0.64.
41- if (reactNativeVersion < 6500 ) {
43+ if (reactNativeVersion > 0 && reactNativeVersion < 6500 ) {
4244 // Artifacts for 0.65+ are published to Maven Central. If we're on an
4345 // older version, we still need to use JCenter.
4446 // noinspection JcenterRepositoryObsolete
@@ -70,7 +72,7 @@ project.ext.react = [
7072 enableFabric : isFabricEnabled(project),
7173 enableFlipper : getFlipperVersion(rootDir),
7274 enableHermes : true ,
73- enableNewArchitecture : isNewArchitectureEnabled(project) ,
75+ enableNewArchitecture : enableNewArchitecture ,
7476]
7577
7678project. ext. signingConfigs = getSigningConfigs()
@@ -86,7 +88,7 @@ android {
8688
8789 // TODO: Remove this block when minSdkVersion >= 24. See
8890 // https://stackoverflow.com/q/53402639 for details.
89- if (reactNativeVersion < 6900 ) {
91+ if (reactNativeVersion > 0 && reactNativeVersion < 6900 ) {
9092 compileOptions {
9193 sourceCompatibility(JavaVersion . VERSION_1_8 )
9294 targetCompatibility(JavaVersion . VERSION_1_8 )
@@ -95,7 +97,7 @@ android {
9597
9698 kotlinOptions {
9799 allWarningsAsErrors = true
98- if (reactNativeVersion < 6900 ) {
100+ if (reactNativeVersion > 0 && reactNativeVersion < 6900 ) {
99101 jvmTarget = JavaVersion . VERSION_1_8
100102 } else {
101103 jvmTarget = JavaVersion . VERSION_11
@@ -129,7 +131,7 @@ android {
129131
130132 if (project. ext. react. enableNewArchitecture) {
131133 externalNativeBuild {
132- if (reactNativeVersion < 7000 ) {
134+ if (reactNativeVersion > 0 && reactNativeVersion < 7000 ) {
133135 ndkBuild {
134136 arguments " APP_PLATFORM=android-${ project.ext.minSdkVersion} " ,
135137 " APP_STL=c++_shared" ,
@@ -172,7 +174,7 @@ android {
172174
173175 if (project. ext. react. enableNewArchitecture) {
174176 externalNativeBuild {
175- if (reactNativeVersion < 7000 ) {
177+ if (reactNativeVersion > 0 && reactNativeVersion < 7000 ) {
176178 ndkBuild {
177179 path " ${ projectDir} /src/main/jni/Android.mk"
178180 }
@@ -199,7 +201,7 @@ android {
199201 preDebugBuild. dependsOn(packageReactNdkDebugLibs)
200202 preReleaseBuild. dependsOn(packageReactNdkReleaseLibs)
201203
202- if (reactNativeVersion < 7000 ) {
204+ if (reactNativeVersion > 0 && reactNativeVersion < 7000 ) {
203205 // Due to a bug in AGP, we have to explicitly set a dependency
204206 // between configureNdkBuild* tasks and the preBuild tasks. This can
205207 // be removed once this issue is resolved:
@@ -214,7 +216,7 @@ android {
214216 dependsOn(" preReleaseBuild" )
215217 }
216218 }
217- } else if (reactNativeVersion < 7100 ) {
219+ } else if (reactNativeVersion > 0 && reactNativeVersion < 7100 ) {
218220 // Due to a bug in AGP, we have to explicitly set a dependency
219221 // between configureCMakeDebug* tasks and the preBuild tasks. This can
220222 // be removed once this issue is resolved:
@@ -238,24 +240,31 @@ android {
238240 }
239241 }
240242
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+ }
249257
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+ }
255263
256- afterEvaluate {
257- preDebugBuild. dependsOn(prepareDebugJSI)
258- preReleaseBuild. dependsOn(prepareReleaseJSI)
264+ afterEvaluate {
265+ preDebugBuild. dependsOn(prepareDebugJSI)
266+ preReleaseBuild. dependsOn(prepareReleaseJSI)
267+ }
259268 }
260269 }
261270
@@ -320,7 +329,7 @@ android {
320329
321330 // TODO: Remove this block when we drop support for 0.67.
322331 // https://github.com/facebook/react-native/commit/ce74aa4ed335d4c36ce722d47937b582045e05c4
323- if (reactNativeVersion < 6800 ) {
332+ if (reactNativeVersion > 0 && reactNativeVersion < 6800 ) {
324333 main. java. srcDirs + = " src/reactinstanceeventlistener-pre-0.68/java"
325334 } else {
326335 main. java. srcDirs + = " src/reactinstanceeventlistener-0.68/java"
@@ -341,8 +350,14 @@ dependencies {
341350 implementation project(" :support" )
342351
343352 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.
346361 def hermesEngineDir =
347362 findNodeModulesPath(" hermes-engine" , reactNativePath)
348363 ?: findNodeModulesPath(" hermesvm" , reactNativePath)
@@ -353,10 +368,6 @@ dependencies {
353368 def hermesAndroidDir = " ${ hermesEngineDir} /android"
354369 releaseImplementation files(" ${ hermesAndroidDir} /hermes-release.aar" )
355370 debugImplementation files(" ${ hermesAndroidDir} /hermes-debug.aar" )
356- } else {
357- implementation(" com.facebook.react:hermes-engine:+" ) {
358- exclude(group : " com.facebook.fbjni" )
359- }
360371 }
361372 }
362373
@@ -370,7 +381,7 @@ dependencies {
370381 implementation libraries. kotlinStdlibJdk8
371382 implementation libraries. kotlinReflect
372383
373- if (reactNativeVersion < 6800 ) {
384+ if (reactNativeVersion > 0 && reactNativeVersion < 6800 ) {
374385 // androidx.appcompat:appcompat:1.4.0+ breaks TextInput. This was fixed
375386 // in react-native 0.68. For more details, see
376387 // https://github.com/facebook/react-native/issues/31572.
0 commit comments