Skip to content

Commit 53c90d6

Browse files
committed
Upgrade Gradle to 9.4 (AGP to 9.1, Kotlin to 2.3)
## Summary: Follow-up to + #55453 + react-native-community/template#205 - bump Gradle wrappers 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 (RNGP) - bump RNGP Kotlin compiler API ver from KOTLIN_1_8 to KOTLIN_2_3 (RNGP) - AGP 9 DSL syntax updates - NB: AGP 9.1 removed direct prop accessors, replaced by lambdas (DSL closures) - ReactPlugin.kt - fix: arg type mismatch: actual type is File, String expected - old .asFile returns File, directories.add() needs String, use .asFile.absolutePath to convert File to String path - NB: AGP 9 replaced .srcDir with directories.add, expects String paths (not File objects) - AgpConfiguratorUtils.kt - fix: unresolved ref 'namespace', update to lambdas - fix: NoSuchMethodError for buildFeatures, 'LibraryBuildFeatures LibraryExtension.getBuildFeatures()', update to lambdas - NdkConfiguratorUtils.kt - fix: com.android.build.api.dsl. ApplicationBuildFeatures ApplicationExtension.getBuildFeatures breaking rn-tester createBundleReleaseJsAndAssets, update to lambdas - fix: com.android.build.api.dsl. ApplicationDefaultConfig ApplicationExtension.getDefaultConfig() breaking rn-tester createBundleReleaseJsAndAssets, update to lambdas - ReactAndroid/build.gradle.kts - fix: java.exclude Unresolved ref 2 script compilation errors - refactor legacy Java source exclusion to explicit filter patterns (Ant-style globs) - NB: AGP 9 AndroidSourceDirectorySet stopped extending PatternFilterable - JsonUtilsTest.kt - fix: :gradle-plugin:shared:compileTestKotlin 40 warnings as errors Unnecessary non-null assertion (!!) on a non-null receiver - assert null once at entry point of vars as done in past Then follow-up react-native-community/template gradlew and kotlinVersion updates e.g. leotm/react-native-template-new-architecture#1933 ## Changelog: [ANDROID] [CHANGED] - Gradle to 9.4.0, Kotlin 2.3.0 and AGP 9.1.0 support ## Test Plan: + template: leotm/react-native-template-new-architecture#1933 - locally (windows 11, CMake: 3.30.5, 4.3.1, JDK 17, JDK 26 security incompatible) - .github/actions/build-android/action.yml with prebuilt stable com.facebook.hermes:hermes-android:0.16.0 artifact from mvnrepository.com/artifact/com.facebook.hermes/hermes-android/0.16.0 - useHermesStable=true, useHermesNightly=false, hermesV1Enabled=false, .hermesversion, version.properties - set: ANDROID_SDK_ROOT, JAVA_HOME, NODE_HOME (prepend all to PATH) - .\gradlew :packages:react-native:ReactAndroid:tasks - .\gradlew :packages:react-native:ReactAndroid:build --dry-run - .\gradlew :packages:react-native:ReactAndroid:buildCodegenCLI -PreactNativeArchitectures=arm64-v8a PenableWarningsAsErrors=true --no-daemon - fix buildCodegenCLI locally for Windows Git Bash compat - .\gradlew :gradle-plugin:react-native-gradle-plugin:compileKotlin -PenableWarningsAsErrors=true --no-daemon - .\gradlew :packages:rn-tester:android:app:createBundleReleaseJsAndAssets -PenableWarningsAsErrors=true --no-daemon - .\gradlew :packages:react-native:ReactAndroid:buildCMakeDebug[arm64-v8a][hermestooling,jsi,etc] -PenableWarningsAsErrors=true --no-daemon - .\gradlew :packages:react-native:ReactAndroid:build -PreactNativeArchitectures=arm64-v8a -PenableWarningsAsErrors=true --no-daemon - .github\actions\build-fantom-runner\action.yml locally requires private:react-native-fantom and compiling hermes from source w debug flags (SLOW af)
1 parent d1809f0 commit 53c90d6

13 files changed

Lines changed: 108 additions & 95 deletions

File tree

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,16 @@ class ReactPlugin : Plugin<Project> {
231231
// This equivalent to this DSL:
232232
//
233233
// android { sourceSets { main { java { srcDirs += "$generatedSrcDir/java" } } } }
234+
// NB: .srcDir (any) deprecated in AGP 9 in favour of .directories (typed) mutable set
234235
if (isLibrary) {
235236
project.extensions.getByType(LibraryAndroidComponentsExtension::class.java).finalizeDsl { ext
236237
->
237-
ext.sourceSets.getByName("main").java.srcDir(generatedSrcDir.get().dir("java").asFile)
238+
ext.sourceSets.getByName("main").java.directories.add(generatedSrcDir.get().dir("java").asFile.absolutePath)
238239
}
239240
} else {
240241
project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java).finalizeDsl {
241242
ext ->
242-
ext.sourceSets.getByName("main").java.srcDir(generatedSrcDir.get().dir("java").asFile)
243+
ext.sourceSets.getByName("main").java.directories.add(generatedSrcDir.get().dir("java").asFile.absolutePath)
243244
}
244245
}
245246

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

Lines changed: 26 additions & 23 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,20 @@ 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+
ext.defaultConfig {
63+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true")
64+
buildConfigField(
65+
"boolean",
66+
"IS_HERMES_ENABLED",
67+
project.isHermesEnabled.toString(),
68+
)
69+
buildConfigField(
70+
"boolean",
71+
"IS_EDGE_TO_EDGE_ENABLED",
72+
project.isEdgeToEdgeEnabled.toString(),
73+
)
74+
}
7475
}
7576
}
7677
project.pluginManager.withPlugin("com.android.application", action)
@@ -82,7 +83,7 @@ internal object AgpConfiguratorUtils {
8283
subproject.pluginManager.withPlugin("com.android.library") {
8384
subproject.extensions
8485
.getByType(LibraryAndroidComponentsExtension::class.java)
85-
.finalizeDsl { ext -> ext.buildFeatures.buildConfig = true }
86+
.finalizeDsl { ext -> ext.buildFeatures { buildConfig = true } }
8687
}
8788
}
8889
}
@@ -97,13 +98,15 @@ internal object AgpConfiguratorUtils {
9798
project.extensions
9899
.getByType(ApplicationAndroidComponentsExtension::class.java)
99100
.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)
101+
ext.buildFeatures { resValues = true }
102+
ext.defaultConfig {
103+
resValue(
104+
"string",
105+
"react_native_dev_server_ip",
106+
devServerIp,
107+
)
108+
resValue("integer", "react_native_dev_server_port", devServerPort)
109+
}
107110
}
108111
}
109112

@@ -118,8 +121,8 @@ internal object AgpConfiguratorUtils {
118121
.getByType(LibraryAndroidComponentsExtension::class.java)
119122
.finalizeDsl { ext ->
120123
if (ext.namespace == null) {
121-
val android = subproject.extensions.getByType(LibraryExtension::class.java)
122-
val manifestFile = android.sourceSets.getByName("main").manifest.srcFile
124+
val manifestFile =
125+
subproject.file("src/main/AndroidManifest.xml")
123126

124127
manifestFile
125128
.takeIf { it.exists() }

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal object NdkConfiguratorUtils {
2222
ext ->
2323
// We enable prefab so users can consume .so/headers from ReactAndroid and hermes-engine
2424
// .aar
25-
ext.buildFeatures.prefab = true
25+
ext.buildFeatures { prefab = true }
2626

2727
// If the user has not provided a CmakeLists.txt path, let's provide
2828
// the default one from the framework
@@ -36,30 +36,32 @@ internal object NdkConfiguratorUtils {
3636

3737
// Parameters should be provided in an additive manner (do not override what
3838
// 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")
56-
}
39+
ext.defaultConfig {
40+
val cmakeArgs = externalNativeBuild.cmake.arguments
41+
if (cmakeArgs.none { it.startsWith("-DPROJECT_BUILD_DIR") }) {
42+
cmakeArgs.add("-DPROJECT_BUILD_DIR=${project.layout.buildDirectory.get().asFile}")
43+
}
44+
if (cmakeArgs.none { it.startsWith("-DPROJECT_ROOT_DIR") }) {
45+
cmakeArgs.add("-DPROJECT_ROOT_DIR=${project.rootProject.layout.projectDirectory.asFile}")
46+
}
47+
if (cmakeArgs.none { it.startsWith("-DREACT_ANDROID_DIR") }) {
48+
cmakeArgs.add(
49+
"-DREACT_ANDROID_DIR=${extension.reactNativeDir.file("ReactAndroid").get().asFile}"
50+
)
51+
}
52+
if (cmakeArgs.none { it.startsWith("-DANDROID_STL") }) {
53+
cmakeArgs.add("-DANDROID_STL=c++_shared")
54+
}
55+
if (cmakeArgs.none { it.startsWith("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES") }) {
56+
cmakeArgs.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON")
57+
}
5758

58-
val architectures = project.getReactNativeArchitectures()
59-
// abiFilters are split ABI are not compatible each other, so we set the abiFilters
60-
// only if the user hasn't enabled the split abi feature.
61-
if (architectures.isNotEmpty() && !ext.splits.abi.isEnable) {
62-
ext.defaultConfig.ndk.abiFilters.addAll(architectures)
59+
val architectures = project.getReactNativeArchitectures()
60+
// abiFilters are split ABI are not compatible each other, so we set the abiFilters
61+
// only if the user hasn't enabled the split abi feature.
62+
if (architectures.isNotEmpty() && !ext.splits.abi.isEnable) {
63+
ndk.abiFilters.addAll(architectures)
64+
}
6365
}
6466
}
6567
}

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)