From 69dc655005bc20feb119ddeca7f663d2d64a6275 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Mon, 13 Oct 2025 18:16:18 -0700 Subject: [PATCH] RNGP - Fix build failures encounted with AGP 9.0.0-alpha05 - Round 1 (#53778) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53778 I've been looking into the next major bump of AGP to 9: https://developer.android.com/build/releases/agp-preview#android-gradle-plugin-built-in-kotlin This change adapts our project so that it keeps on buildign with AGP 8 (as the bump to 9 would be a breaking change), but it addresses some of the build failures we'll be having with AGP 9: - Set `resValues` build option to true (default was changed true -> false in AGP 9) - Opts out our project from `android.builtInKotlin` and `android.newDsl` for the time being. Changelog: [Android] [Fixed] - Fix build failures with RNGP due to AGP 9.0.0-alpha05 Reviewed By: alanleedev Differential Revision: D82452555 fbshipit-source-id: 99561f039bf943f5ce99008ce073ca86431cfaed --- gradle.properties | 7 +++++++ .../facebook/react/utils/AgpConfiguratorUtils.kt | 1 + packages/react-native/ReactAndroid/build.gradle.kts | 13 ++++++++----- .../devsupport/CxxInspectorPackagerConnection.kt | 1 + 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index e59a251afa6..0a91ef0f755 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,6 +4,13 @@ org.gradle.caching=true android.useAndroidX=true +# Those 2 properties are needed to make our project compatible with +# AGP 9.0.0 for the time being. Ideally we should not opt-out of +# builtInKotlin and newDsl once AGP 9.0.0 hits stable. +# More on this: https://developer.android.com/build/releases/agp-preview#android-gradle-plugin-built-in-kotlin +android.builtInKotlin=false +android.newDsl=false + # Use this property to specify which architecture you want to build. # You can also override it from the CLI using # ./gradlew -PreactNativeArchitectures=x86_64 diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt index ab011c2d41f..d8a3d7f529f 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt @@ -100,6 +100,7 @@ internal object AgpConfiguratorUtils { project.extensions .getByType(ApplicationAndroidComponentsExtension::class.java) .finalizeDsl { ext -> + ext.buildFeatures.resValues = true ext.defaultConfig.resValue( "string", "react_native_dev_server_ip", diff --git a/packages/react-native/ReactAndroid/build.gradle.kts b/packages/react-native/ReactAndroid/build.gradle.kts index 26a460c033e..9df10a70b5f 100644 --- a/packages/react-native/ReactAndroid/build.gradle.kts +++ b/packages/react-native/ReactAndroid/build.gradle.kts @@ -532,11 +532,13 @@ android { targetCompatibility = JavaVersion.VERSION_17 } - kotlinOptions { - // Using '-Xjvm-default=all' to generate default java methods for interfaces - freeCompilerArgs = listOf("-Xjvm-default=all") - // Using -PenableWarningsAsErrors=true prop to enable allWarningsAsErrors - kotlinOptions.allWarningsAsErrors = enableWarningsAsErrors() + kotlin { + compilerOptions { + // Using '-Xjvm-default=all' to generate default java methods for interfaces + freeCompilerArgs = listOf("-Xjvm-default=all") + // Using -PenableWarningsAsErrors=true prop to enable allWarningsAsErrors + allWarningsAsErrors = enableWarningsAsErrors() + } } defaultConfig { @@ -637,6 +639,7 @@ android { prefab = true prefabPublishing = true buildConfig = true + resValues = true } prefab { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/CxxInspectorPackagerConnection.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/CxxInspectorPackagerConnection.kt index b1a87c32a6c..a92d4ac26c6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/CxxInspectorPackagerConnection.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/CxxInspectorPackagerConnection.kt @@ -22,6 +22,7 @@ import okhttp3.WebSocket import okhttp3.WebSocketListener /** Java wrapper around a C++ InspectorPackagerConnection. */ +@DoNotStripAny internal class CxxInspectorPackagerConnection( url: String, deviceName: String,