Skip to content

Commit 6abb93b

Browse files
hurali97m-bert
andcommitted
feat: Adopt AGP v9 (#4263)
## Description <!-- Description and motivation for this PR. Include 'Fixes #<number>' if this is fixing some issue. --> This PR is rasied following the second phase of the RFC around AGP v9 adoption: RFC: react-native-community/discussions-and-proposals#1006 The gist of this PR is to make Gesture Handler AGP v9 compliant with backward compatibility. The main scope of changes is the `react-native-gesture-handler/android/build.gradle`. The rest of the changes can be considered temporary. The rest changes include: - Making Basic Example App AGP9 compliant - Upgrade `Gradle` to `v9.4.1` - Use `proguard-android-optimize` proguard file - Enable opt outs in the `gradle.properties` Ideally, we should not enable the opt outs and leverage the AGP 9 built-in kotlin and newDSL. However, if we do not do it, then other libraries which are not yet AGP v9 compliant starts to fail. Hence, we need to keep the opt outs enabled for a while. For the context, react-native starting from 0.87.x will ship with AGP v9 and opt outs enabled by default for the new apps, which is the first phase of AGP v9 adoption. With the second phase when the libraries starts adoption AGP v9, we can eventually remove the opt outs from Basic Example. ## Test plan <!-- Describe how did you test this change here. --> To test this PR, we need to do a few steps: - Set the `agp` version to `9.2.1` and `kotlin` to `2.2.0` in `react-native-gradle-plugin` ```diff --- a/node_modules/@react-native/gradle-plugin/gradle/libs.versions.toml +++ b/node_modules/@react-native/gradle-plugin/gradle/libs.versions.toml @@ -1,10 +1,10 @@ [versions] -agp = "8.12.0" +agp = "9.2.1" gson = "2.8.9" -kotlin = "2.1.20" +kotlin = "2.2.0" assertj = "3.25.1" ``` - Comment out the following functions in `react-native-gradle-plugin` ```diff --- a/node_modules/@react-native/gradle-plugin/react-native-gradle-plugin/ReactPlugin.kt +++ b/node_modules/@react-native/gradle-plugin/react-native-gradle-plugin/ReactPlugin.kt @@ -1,10 +1,10 @@ configureBuildTypesForApp(project) } // Library Only Configuration - configureBuildConfigFieldsForLibraries(project) - configureNamespaceForLibraries(project) + // configureBuildConfigFieldsForLibraries(project) + // configureNamespaceForLibraries(project) project.pluginManager.withPlugin("com.android.library") { ``` This step is only required because we have RN version on 0.85.2 and `AGP` + `kotlin` bump will be shipped with 0.87.x. <details> <summary>Verified by locally patching Reanimated and Worklet, making those AGP v9 compliant and removing the opt outs to test the changes in the PR </summary> https://github.com/user-attachments/assets/7f4f571a-6bef-4694-9b32-330571c0c734 </details> <details> <summary>Verified these changes work with AGP 8 </summary> https://github.com/user-attachments/assets/116a0b2e-23f5-499c-8a64-b99f927165c4 </details> --------- Co-authored-by: Michał <michal.bert@swmansion.com>
1 parent 0927dd8 commit 6abb93b

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,22 @@ if (isNewArchitectureEnabled()) {
6363
}
6464

6565
apply plugin: 'com.android.library'
66-
apply plugin: 'kotlin-android'
66+
67+
def shouldEnableAgpFallback() {
68+
def agpMajorVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
69+
if (agpMajorVersion <= 8) {
70+
return true
71+
}
72+
73+
def propertyVal = providers.gradleProperty("android.builtInKotlin").orNull
74+
def isBuiltInKotlinEnabled = propertyVal != null ? propertyVal.toBoolean() : true
75+
76+
return !isBuiltInKotlinEnabled
77+
}
78+
79+
if (shouldEnableAgpFallback()) {
80+
apply plugin: 'kotlin-android'
81+
}
6782

6883
if (project == rootProject) {
6984
apply from: "spotless.gradle"
@@ -191,17 +206,17 @@ android {
191206
}
192207

193208
sourceSets.main {
194-
java {
209+
kotlin {
195210
if (shouldUseCommonInterfaceFromReanimated()) {
196-
srcDirs += 'reanimated/src/main/java'
211+
directories.add('reanimated/src/main/java')
197212
} else {
198-
srcDirs += 'noreanimated/src/main/java'
213+
directories.add('noreanimated/src/main/java')
199214
}
200215

201216
if (shouldUseCommonInterfaceFromRNSVG()) {
202-
srcDirs += 'svg/src/main/java'
217+
directories.add('svg/src/main/java')
203218
} else {
204-
srcDirs += 'nosvg/src/main/java'
219+
directories.add('nosvg/src/main/java')
205220
}
206221

207222
if (isNewArchitectureEnabled()) {

0 commit comments

Comments
 (0)