Skip to content

Commit 778cab5

Browse files
authored
[Android] Update build tools (#3544)
>[!IMPORTANT] > Replaces #3538 ## Description Seems like we fallen behind with our build tools dependencies. This PR: - Bumps `Kotlin` version to 2.0.21 - Updates `gradle` - Removes build warnings - Removes sourceSets for unsupported versions of RN ## Test plan - Run `yarn android` in `basic-example` and `expo-example` - Run `yarn format:android`
1 parent a8f73c2 commit 778cab5

File tree

15 files changed

+51
-340
lines changed

15 files changed

+51
-340
lines changed

packages/react-native-gesture-handler/android/build.gradle

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ buildscript {
1111

1212
dependencies {
1313
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
14-
classpath("com.android.tools.build:gradle:7.2.1")
15-
classpath("com.diffplug.spotless:spotless-plugin-gradle:7.0.3")
14+
classpath("com.android.tools.build:gradle:8.10.1")
15+
classpath("com.diffplug.spotless:spotless-plugin-gradle:7.0.4")
1616
}
1717
}
1818

@@ -45,6 +45,7 @@ def resolveReactNativeDirectory() {
4545
commandLine("node", "--print", "require.resolve('react-native/package.json')")
4646
}.standardOutput.asText.get().trim()
4747
)
48+
4849
if (reactNativePackage.exists()) {
4950
return reactNativePackage.parentFile
5051
}
@@ -59,41 +60,53 @@ def resolveReactNativeDirectory() {
5960
if (isNewArchitectureEnabled()) {
6061
apply plugin: 'com.facebook.react'
6162
}
63+
6264
apply plugin: 'com.android.library'
6365
apply plugin: 'kotlin-android'
6466

6567
if (project == rootProject) {
6668
apply from: "spotless.gradle"
6769
}
6870

71+
def getExternalLibVersion(project){
72+
def inputFile = new File(project.projectDir, "../package.json")
73+
def json = new JsonSlurper().parseText(inputFile.text)
74+
def libVerision = json.version as String
75+
def (major, minor, patch) = libVerision.tokenize('.')
76+
77+
// Handle cases where version is a pre-release one, e.g. "2.3.0-alpha.1"
78+
def patchVersion = patch.find(/(\d+)/) ? patch.find(/(\d+)/) : "0"
79+
80+
return [Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patchVersion)]
81+
}
82+
6983
// Check whether Reanimated 2.3 or higher is installed alongside Gesture Handler
7084
def shouldUseCommonInterfaceFromReanimated() {
7185
def reanimated = rootProject.subprojects.find { it.name == 'react-native-reanimated' }
72-
if (reanimated != null) {
73-
def inputFile = new File(reanimated.projectDir, '../package.json')
74-
def json = new JsonSlurper().parseText(inputFile.text)
75-
def reanimatedVersion = json.version as String
76-
def (major, minor, patch) = reanimatedVersion.tokenize('.')
77-
return (Integer.parseInt(major) == 2 && Integer.parseInt(minor) >= 3) || Integer.parseInt(major) >= 3
78-
} else {
86+
87+
if (reanimated == null) {
7988
return false
8089
}
90+
91+
def (major, minor, patch) = getExternalLibVersion(reanimated)
92+
93+
return (major == 2 && minor >= 3) || major >= 3
8194
}
8295

8396
def shouldUseCommonInterfaceFromRNSVG() {
8497
// common interface compatible with react-native-svg >= 15.11.2
8598
def rnsvg = rootProject.subprojects.find { it.name == 'react-native-svg' }
99+
86100
if (rnsvg == null) {
87101
return false
88102
}
89103

90-
def inputFile = new File(rnsvg.projectDir, '../package.json')
91-
def json = new JsonSlurper().parseText(inputFile.text)
92-
def rnsvgVersion = json.version as String
93-
def (major, minor, patch) = rnsvgVersion.tokenize('.')
94-
return (Integer.parseInt(major) == 15 && Integer.parseInt(minor) == 11 && Integer.parseInt(patch) >= 2) ||
95-
(Integer.parseInt(major) == 15 && Integer.parseInt(minor) > 11) ||
96-
Integer.parseInt(major) > 15
104+
def (major, minor, patch) = getExternalLibVersion(rnsvg)
105+
106+
107+
return (major == 15 && minor == 11 && patch >= 2) ||
108+
(major == 15 && minor > 11) ||
109+
major > 15
97110
}
98111

99112
def reactNativeArchitectures() {
@@ -107,7 +120,7 @@ def reactProperties = new Properties()
107120
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
108121

109122
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
110-
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
123+
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
111124

112125
repositories {
113126
mavenCentral()
@@ -116,7 +129,7 @@ repositories {
116129
android {
117130
compileSdkVersion safeExtGet("compileSdkVersion", 33)
118131

119-
namespace "com.swmansion.gesturehandler"
132+
namespace = "com.swmansion.gesturehandler"
120133
buildFeatures {
121134
buildConfig = true
122135
prefab = true
@@ -132,10 +145,8 @@ android {
132145
}
133146

134147
defaultConfig {
135-
minSdkVersion safeExtGet('minSdkVersion', 21)
148+
minSdkVersion safeExtGet('minSdkVersion', 24)
136149
targetSdkVersion safeExtGet('targetSdkVersion', 33)
137-
versionCode 1
138-
versionName "1.0"
139150
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
140151
buildConfigField "int", "REACT_NATIVE_MINOR_VERSION", REACT_NATIVE_MINOR_VERSION.toString()
141152

@@ -180,12 +191,9 @@ android {
180191

181192
sourceSets.main {
182193
java {
183-
// Include "common/" only when it's not provided by Reanimated to mitigate
184-
// multiple definitions of the same class preventing build
185194
if (shouldUseCommonInterfaceFromReanimated()) {
186195
srcDirs += 'reanimated/src/main/java'
187196
} else {
188-
srcDirs += 'common/src/main/java'
189197
srcDirs += 'noreanimated/src/main/java'
190198
}
191199

@@ -200,21 +208,7 @@ android {
200208
} else {
201209
// 'paper/src/main/java' includes files from codegen so the library can compile with
202210
// codegen turned off
203-
204-
if (REACT_NATIVE_MINOR_VERSION > 77) {
205-
srcDirs += 'paper/src/main/java'
206-
} else {
207-
srcDirs += 'paper77/src/main/java'
208-
}
209-
}
210-
211-
if (REACT_NATIVE_MINOR_VERSION >= 77) {
212-
// With RN 0.77, ViewManager related functions in the package has different signatures as they
213-
// are no longer nullable
214-
srcDirs += 'package77/src/main/java'
215-
} else {
216-
// It's safe to delete this block once we drop support for RN 0.76
217-
srcDirs += 'packageDeprecated/src/main/java'
211+
srcDirs += 'paper/src/main/java'
218212
}
219213
}
220214
}
@@ -252,7 +246,7 @@ dependencies {
252246
implementation rootProject.subprojects.find { it.name == 'react-native-svg' }
253247
}
254248

255-
implementation 'androidx.appcompat:appcompat:1.2.0'
256-
implementation "androidx.core:core-ktx:1.6.0"
249+
implementation 'androidx.appcompat:appcompat:1.7.0'
250+
implementation "androidx.core:core-ktx:1.16.0"
257251
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
258252
}

packages/react-native-gesture-handler/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemor
1616
# This option should only be used with decoupled projects. More details, visit
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
19-
RNGH_kotlinVersion=1.6.21
19+
RNGH_kotlinVersion=2.0.21
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

packages/react-native-gesture-handler/android/gradlew

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ set -- \
205205
org.gradle.wrapper.GradleWrapperMain \
206206
"$@"
207207

208+
# Stop when "xargs" is not available.
209+
if ! command -v xargs >/dev/null 2>&1
210+
then
211+
die "xargs is not available"
212+
fi
213+
208214
# Use "xargs" to parse quoted args.
209215
#
210216
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

packages/react-native-gesture-handler/android/gradlew.bat

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@rem limitations under the License.
1515
@rem
1616

17-
@if "%DEBUG%" == "" @echo off
17+
@if "%DEBUG%"=="" @echo off
1818
@rem ##########################################################################
1919
@rem
2020
@rem Gradle startup script for Windows
@@ -25,7 +25,7 @@
2525
if "%OS%"=="Windows_NT" setlocal
2626

2727
set DIRNAME=%~dp0
28-
if "%DIRNAME%" == "" set DIRNAME=.
28+
if "%DIRNAME%"=="" set DIRNAME=.
2929
set APP_BASE_NAME=%~n0
3030
set APP_HOME=%DIRNAME%
3131

@@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4040

4141
set JAVA_EXE=java.exe
4242
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
43+
if %ERRORLEVEL% equ 0 goto execute
4444

4545
echo.
4646
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7575

7676
:end
7777
@rem End local scope for the variables with windows NT shell
78-
if "%ERRORLEVEL%"=="0" goto mainEnd
78+
if %ERRORLEVEL% equ 0 goto mainEnd
7979

8080
:fail
8181
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
8282
rem the _cmd.exe /c_ return code!
83-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84-
exit /b 1
83+
set EXIT_CODE=%ERRORLEVEL%
84+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
85+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
86+
exit /b %EXIT_CODE%
8587

8688
:mainEnd
8789
if "%OS%"=="Windows_NT" endlocal

packages/react-native-gesture-handler/android/packageDeprecated/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt

Lines changed: 0 additions & 80 deletions
This file was deleted.

packages/react-native-gesture-handler/android/paper77/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)