Skip to content

Commit ef74c63

Browse files
authored
fix(android): workaround for dynamic version issues (#1193)
New `react-native` versions are being published to Maven causing havoc with older versions. This works around the issue. For more details, see facebook/react-native#35210
1 parent 8e5c895 commit ef74c63

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

android/app/build.gradle

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ plugins {
1313
def enableNewArchitecture = isNewArchitectureEnabled(project)
1414
def reactNativeVersion = getPackageVersionNumber("react-native", rootDir)
1515
def reactNativePath = file(findNodeModulesPath("react-native", rootDir))
16-
def codegenPath = file(findNodeModulesPath("react-native-codegen", reactNativePath))
1716

1817
if (reactNativeVersion == 0 || enableNewArchitecture) {
1918
apply(plugin: "com.facebook.react")
2019

2120
if (enableNewArchitecture) {
2221
react {
23-
codegenDir = codegenPath
22+
codegenDir = file(findNodeModulesPath("react-native-codegen", reactNativePath))
2423
reactNativeDir = reactNativePath
2524
}
2625
}
@@ -245,7 +244,7 @@ android {
245244
// `.gradle/caches/modules-2/files-2.1/com.facebook.react/react-native`.
246245
// For now, we will simply disable this step as we only need to verify
247246
// that things build.
248-
if (reactNativeVersion > 0) {
247+
if (reactNativeVersion > 0 && reactNativeVersion < 7100) {
249248
def version = getPackageVersion("react-native", rootDir)
250249
def allAar = file("${reactNativePath}/android/com/facebook/react/react-native/${version}/react-native-${version}.aar")
251250

@@ -373,8 +372,11 @@ dependencies {
373372

374373
if (project.ext.react.enableNewArchitecture) {
375374
implementation project(":ReactAndroid")
375+
} else if (reactNativeVersion == 0 || reactNativeVersion >= 7100) {
376+
implementation("com.facebook.react:react-native")
376377
} else {
377-
implementation "com.facebook.react:react-native:+"
378+
def version = getPackageVersion("react-native", rootDir)
379+
implementation("com.facebook.react:react-native:${version}")
378380
}
379381

380382
implementation libraries.kotlinStdlibJdk7
@@ -434,6 +436,16 @@ if (project.ext.react.enableNewArchitecture) {
434436
.because("On New Architecture, we are building Hermes from source")
435437
}
436438
}
439+
} else if (reactNativeVersion > 0 && reactNativeVersion < 7100) {
440+
configurations.all {
441+
resolutionStrategy {
442+
// Force version here otherwise Gradle will pick up a newer version:
443+
// https://github.com/facebook/react-native/issues/35210
444+
def version = getPackageVersion("react-native", rootDir)
445+
force("com.facebook.react:react-native:${version}")
446+
force("com.facebook.react:hermes-engine:${version}")
447+
}
448+
}
437449
}
438450

439451
// `@react-native-community/cli` currently requires this function to be defined.

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ buildscript {
1414
def isNightly = getPackageVersionNumber("react-native", rootDir) == 0
1515
if (isNightly || isNewArchitectureEnabled(project)) {
1616
classpath("com.facebook.react:react-native-gradle-plugin")
17-
classpath("de.undercouch:gradle-download-task:5.2.1")
17+
classpath("de.undercouch:gradle-download-task:5.3.0")
1818
}
1919
}
2020
}

scripts/configure.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ const getConfig = (() => {
487487
"",
488488
" if (isNewArchitectureEnabled(project)) {",
489489
' classpath("com.facebook.react:react-native-gradle-plugin")',
490-
' classpath("de.undercouch:gradle-download-task:5.2.1")',
490+
' classpath("de.undercouch:gradle-download-task:5.3.0")',
491491
" }",
492492
" }",
493493
"}",

test/configure/__snapshots__/gatherConfig.test.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Object {
8484
8585
if (isNewArchitectureEnabled(project)) {
8686
classpath(\\"com.facebook.react:react-native-gradle-plugin\\")
87-
classpath(\\"de.undercouch:gradle-download-task:5.2.1\\")
87+
classpath(\\"de.undercouch:gradle-download-task:5.3.0\\")
8888
}
8989
}
9090
}
@@ -386,7 +386,7 @@ Object {
386386
387387
if (isNewArchitectureEnabled(project)) {
388388
classpath(\\"com.facebook.react:react-native-gradle-plugin\\")
389-
classpath(\\"de.undercouch:gradle-download-task:5.2.1\\")
389+
classpath(\\"de.undercouch:gradle-download-task:5.3.0\\")
390390
}
391391
}
392392
}
@@ -537,7 +537,7 @@ Object {
537537
538538
if (isNewArchitectureEnabled(project)) {
539539
classpath(\\"com.facebook.react:react-native-gradle-plugin\\")
540-
classpath(\\"de.undercouch:gradle-download-task:5.2.1\\")
540+
classpath(\\"de.undercouch:gradle-download-task:5.3.0\\")
541541
}
542542
}
543543
}

0 commit comments

Comments
 (0)