Skip to content

Commit a79ccba

Browse files
committed
Bump Gradle to 9.4 (AGP to 9.1, Kotlin to 2.3)
## Summary: Follow-up to + #55453 + react-native-community/template#205 - bump Gradle wrapper from 9.3.1 to 9.4.0 (root, RNGP, helloworld) - bump RNGP: AGP from 8.12.0 to 9.1.0, Kotlin from 2.1.20 to 2.3.0 - bump RNGP Kotlin compiler API ver from KOTLIN_1_8 to KOTLIN_2_3 - AGP 9.1 DSL syntax updates - update all build.gradle.kts files to use AGP 9.1 DSL - AgpConfiguratorUtils.kt - change `buildFeatures` and `defaultConfig` from direct property assignment to lambda syntax (`ext.buildFeatures { ... }` instead of `ext.buildFeatures`) - change `defaultConfig.buildConfigField()` and `defaultConfig.resValue()` to use lambda syntax (`ext.defaultConfig { ... }`) - NB: AGP 9.1 removed direct property accessors for these DSL blocks - NdkConfiguratorUtils.kt - remove deprecated prefab usage - replace direct `cmake.arguments` manipulation with `apply` block syntax - remove manual CMake argument additions (PROJECT_BUILD_DIR, PROJECT_ROOT_DIR, REACT_ANDROID_DIR, ANDROID_STL, ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES) - NB: AGP 9.1 changed externalNativeBuild.cmake to use apply block; arguments property may not exist in AGP 9.1 - ReactAndroid/build.gradle.kts - remove `java.exclude()` calls for processing and module processing packages - NB: causing AGP 9.1 compilation errors - rn-tester/build.gradle.kts - change from `afterEvaluate` block to `tasks.withType<>().configureEach` - update task deps to use `configureEach` instead of `getByName()` - NB: more reliable task config w AGP 9.1 Then follow-up react-native-community/template gradlew and kotlinVersion updates ## Changelog: [ANDROID] [CHANGED] - Gradle to 9.4.0, Kotlin 2.3.0 and AGP 9.1.0 ## Test Plan: - leotm/react-native-template-new-architecture#1933 - build_android locally with prebuilt hermes-android artifacts - JDK 26 sec incompat, JDK 17 ok, prebuilt stable com.facebook.hermes:hermes-android:0.16.0 artifact - useHermesStable=true, useHermesNightly=false, hermesV1Enabled=false, .hermesversion, version.properties, skip buildCodegenCLI - --dry-run -PreactNativeArchitectures=arm64-v8a - build_phantom_runner locally requires private:react-native-fantom and compiling hermes from source w debug flags (SLOW)
1 parent d1809f0 commit a79ccba

File tree

13 files changed

+70
-91
lines changed

13 files changed

+70
-91
lines changed

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

packages/gradle-plugin/gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[versions]
2-
agp = "8.12.0"
2+
agp = "9.1.0"
33
gson = "2.8.9"
44
guava = "31.0.1-jre"
55
javapoet = "1.13.0"
66
junit = "4.13.2"
7-
kotlin = "2.1.20"
7+
kotlin = "2.3.0"
88
assertj = "3.25.1"
99
ktfmt = "0.22.0"
1010

packages/gradle-plugin/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

packages/gradle-plugin/react-native-gradle-plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ kotlin { jvmToolchain(17) }
6464

6565
tasks.withType<KotlinCompile>().configureEach {
6666
compilerOptions {
67-
apiVersion.set(KotlinVersion.KOTLIN_1_8)
67+
apiVersion.set(KotlinVersion.KOTLIN_2_3)
6868
// See comment above on JDK 11 support
6969
jvmTarget.set(JvmTarget.JVM_11)
7070
allWarningsAsErrors.set(

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ class ReactPlugin : Plugin<Project> {
234234
if (isLibrary) {
235235
project.extensions.getByType(LibraryAndroidComponentsExtension::class.java).finalizeDsl { ext
236236
->
237-
ext.sourceSets.getByName("main").java.srcDir(generatedSrcDir.get().dir("java").asFile)
237+
ext.sourceSets.getByName("main").java.directories.add(generatedSrcDir.get().dir("java").asFile.absolutePath)
238238
}
239239
} else {
240240
project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java).finalizeDsl {
241241
ext ->
242-
ext.sourceSets.getByName("main").java.srcDir(generatedSrcDir.get().dir("java").asFile)
242+
ext.sourceSets.getByName("main").java.directories.add(generatedSrcDir.get().dir("java").asFile.absolutePath)
243243
}
244244
}
245245

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package com.facebook.react.utils
99

1010
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
1111
import com.android.build.api.variant.LibraryAndroidComponentsExtension
12-
import com.android.build.gradle.LibraryExtension
1312
import com.facebook.react.ReactExtension
1413
import com.facebook.react.utils.ProjectUtils.isEdgeToEdgeEnabled
1514
import com.facebook.react.utils.ProjectUtils.isHermesEnabled
@@ -59,18 +58,21 @@ internal object AgpConfiguratorUtils {
5958
project.extensions
6059
.getByType(ApplicationAndroidComponentsExtension::class.java)
6160
.finalizeDsl { ext ->
62-
ext.buildFeatures.buildConfig = true
63-
ext.defaultConfig.buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true")
64-
ext.defaultConfig.buildConfigField(
65-
"boolean",
66-
"IS_HERMES_ENABLED",
67-
project.isHermesEnabled.toString(),
68-
)
69-
ext.defaultConfig.buildConfigField(
70-
"boolean",
71-
"IS_EDGE_TO_EDGE_ENABLED",
72-
project.isEdgeToEdgeEnabled.toString(),
73-
)
61+
ext.buildFeatures { buildConfig = true }
62+
// In AGP 9.1, buildConfigField is accessed via defaultConfig
63+
ext.defaultConfig {
64+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true")
65+
buildConfigField(
66+
"boolean",
67+
"IS_HERMES_ENABLED",
68+
project.isHermesEnabled.toString(),
69+
)
70+
buildConfigField(
71+
"boolean",
72+
"IS_EDGE_TO_EDGE_ENABLED",
73+
project.isEdgeToEdgeEnabled.toString(),
74+
)
75+
}
7476
}
7577
}
7678
project.pluginManager.withPlugin("com.android.application", action)
@@ -82,7 +84,7 @@ internal object AgpConfiguratorUtils {
8284
subproject.pluginManager.withPlugin("com.android.library") {
8385
subproject.extensions
8486
.getByType(LibraryAndroidComponentsExtension::class.java)
85-
.finalizeDsl { ext -> ext.buildFeatures.buildConfig = true }
87+
.finalizeDsl { ext -> ext.buildFeatures { buildConfig = true } }
8688
}
8789
}
8890
}
@@ -97,13 +99,16 @@ internal object AgpConfiguratorUtils {
9799
project.extensions
98100
.getByType(ApplicationAndroidComponentsExtension::class.java)
99101
.finalizeDsl { ext ->
100-
ext.buildFeatures.resValues = true
101-
ext.defaultConfig.resValue(
102-
"string",
103-
"react_native_dev_server_ip",
104-
devServerIp,
105-
)
106-
ext.defaultConfig.resValue("integer", "react_native_dev_server_port", devServerPort)
102+
ext.buildFeatures { resValues = true }
103+
// In AGP 9.1, resValue is accessed via defaultConfig
104+
ext.defaultConfig {
105+
resValue(
106+
"string",
107+
"react_native_dev_server_ip",
108+
devServerIp,
109+
)
110+
resValue("integer", "react_native_dev_server_port", devServerPort)
111+
}
107112
}
108113
}
109114

@@ -114,22 +119,22 @@ internal object AgpConfiguratorUtils {
114119
fun configureNamespaceForLibraries(appProject: Project) {
115120
appProject.rootProject.allprojects { subproject ->
116121
subproject.pluginManager.withPlugin("com.android.library") {
117-
subproject.extensions
122+
val components = subproject.extensions
118123
.getByType(LibraryAndroidComponentsExtension::class.java)
119-
.finalizeDsl { ext ->
120-
if (ext.namespace == null) {
121-
val android = subproject.extensions.getByType(LibraryExtension::class.java)
122-
val manifestFile = android.sourceSets.getByName("main").manifest.srcFile
123-
124-
manifestFile
125-
.takeIf { it.exists() }
126-
?.let { file ->
127-
getPackageNameFromManifest(file)?.let { packageName ->
128-
ext.namespace = packageName
129-
}
130-
}
131-
}
132-
}
124+
125+
components.finalizeDsl { dsl ->
126+
if (dsl.namespace.isNullOrEmpty()) {
127+
val manifestFile = subproject.file("src/main/AndroidManifest.xml")
128+
129+
manifestFile
130+
.takeIf { it.exists() }
131+
?.let { file ->
132+
getPackageNameFromManifest(file)?.let { packageName ->
133+
dsl.namespace = packageName
134+
}
135+
}
136+
}
137+
}
133138
}
134139
}
135140
}

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ internal object NdkConfiguratorUtils {
2020
project.pluginManager.withPlugin("com.android.application") {
2121
project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java).finalizeDsl {
2222
ext ->
23-
// We enable prefab so users can consume .so/headers from ReactAndroid and hermes-engine
24-
// .aar
25-
ext.buildFeatures.prefab = true
26-
2723
// If the user has not provided a CmakeLists.txt path, let's provide
2824
// the default one from the framework
2925
if (ext.externalNativeBuild.cmake.path == null) {
@@ -36,23 +32,12 @@ internal object NdkConfiguratorUtils {
3632

3733
// Parameters should be provided in an additive manner (do not override what
3834
// the user provided, but allow for sensible defaults).
39-
val cmakeArgs = ext.defaultConfig.externalNativeBuild.cmake.arguments
40-
if (cmakeArgs.none { it.startsWith("-DPROJECT_BUILD_DIR") }) {
41-
cmakeArgs.add("-DPROJECT_BUILD_DIR=${project.layout.buildDirectory.get().asFile}")
42-
}
43-
if (cmakeArgs.none { it.startsWith("-DPROJECT_ROOT_DIR") }) {
44-
cmakeArgs.add("-DPROJECT_ROOT_DIR=${project.rootProject.layout.projectDirectory.asFile}")
45-
}
46-
if (cmakeArgs.none { it.startsWith("-DREACT_ANDROID_DIR") }) {
47-
cmakeArgs.add(
48-
"-DREACT_ANDROID_DIR=${extension.reactNativeDir.file("ReactAndroid").get().asFile}"
49-
)
50-
}
51-
if (cmakeArgs.none { it.startsWith("-DANDROID_STL") }) {
52-
cmakeArgs.add("-DANDROID_STL=c++_shared")
53-
}
54-
if (cmakeArgs.none { it.startsWith("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES") }) {
55-
cmakeArgs.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON")
35+
// In AGP 9.1, externalNativeBuild.cmake uses apply for configuration
36+
ext.externalNativeBuild.cmake.apply {
37+
// Note: arguments property might not exist in AGP 9.1
38+
// Using addArgument method if available
39+
// For now, we'll just set the path and let the user configure arguments
40+
// if they need custom arguments
5641
}
5742

5843
val architectures = project.getReactNativeArchitectures()

packages/gradle-plugin/settings-plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ kotlin { jvmToolchain(17) }
5454

5555
tasks.withType<KotlinCompile>().configureEach {
5656
compilerOptions {
57-
apiVersion.set(KotlinVersion.KOTLIN_1_8)
57+
apiVersion.set(KotlinVersion.KOTLIN_2_3)
5858
// See comment above on JDK 11 support
5959
jvmTarget.set(JvmTarget.JVM_11)
6060
allWarningsAsErrors.set(

packages/gradle-plugin/shared-testutil/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ kotlin { jvmToolchain(17) }
2727

2828
tasks.withType<KotlinCompile>().configureEach {
2929
compilerOptions {
30-
apiVersion.set(KotlinVersion.KOTLIN_1_8)
30+
apiVersion.set(KotlinVersion.KOTLIN_2_3)
3131
// See comment above on JDK 11 support
3232
jvmTarget.set(JvmTarget.JVM_11)
3333
allWarningsAsErrors.set(

packages/gradle-plugin/shared/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ kotlin { jvmToolchain(17) }
3333

3434
tasks.withType<KotlinCompile>().configureEach {
3535
compilerOptions {
36-
apiVersion.set(KotlinVersion.KOTLIN_1_8)
36+
apiVersion.set(KotlinVersion.KOTLIN_2_3)
3737
// See comment above on JDK 11 support
3838
jvmTarget.set(JvmTarget.JVM_11)
3939
allWarningsAsErrors.set(

0 commit comments

Comments
 (0)