From 1c2ff59a0e764235a4892fc737e6a9d2d311be68 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 13 Oct 2023 10:07:10 -0700 Subject: [PATCH] Make sure buildConfig is turned on for all the 3rd party libraries (#40939) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/40939 Currently some libs on RN 0.73 are broken as the default for Build Config generation changed from true to false since AGP 8.x. This reverts the behavior to the old flag. Closes #40791 Closes #40559 Changelog: [Internal] [Changed] - Make sure buildConfig is turned on for all the 3rd party libraries Reviewed By: mdvacca Differential Revision: D50270382 fbshipit-source-id: 02dcb031c577f65be2f41d9da0334c1b3d89e4c5 --- .../main/kotlin/com/facebook/react/ReactPlugin.kt | 6 ++++-- .../com/facebook/react/utils/AgpConfiguratorUtils.kt | 12 +++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 6451e450729313..d87ac2b48c7edf 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -12,7 +12,8 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn import com.facebook.react.internal.PrivateReactExtension import com.facebook.react.tasks.GenerateCodegenArtifactsTask import com.facebook.react.tasks.GenerateCodegenSchemaTask -import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFields +import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFieldsForApp +import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFieldsForLibraries import com.facebook.react.utils.AgpConfiguratorUtils.configureDevPorts import com.facebook.react.utils.BackwardCompatUtils.configureBackwardCompatibilityReactMap import com.facebook.react.utils.DependencyUtils.configureDependencies @@ -64,7 +65,7 @@ class ReactPlugin : Plugin { } configureReactNativeNdk(project, extension) - configureBuildConfigFields(project) + configureBuildConfigFieldsForApp(project) configureDevPorts(project) configureBackwardCompatibilityReactMap(project) @@ -83,6 +84,7 @@ class ReactPlugin : Plugin { // Library and App Configurations configureJavaToolChains(project) + configureBuildConfigFieldsForLibraries(project) } private fun checkJvmVersion(project: Project) { diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt index 3e9f8fc5e7a2ff..17498a15e552ea 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt @@ -17,7 +17,7 @@ import org.gradle.api.plugins.AppliedPlugin @Suppress("UnstableApiUsage") internal object AgpConfiguratorUtils { - fun configureBuildConfigFields(project: Project) { + fun configureBuildConfigFieldsForApp(project: Project) { val action = Action { project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext -> @@ -32,6 +32,16 @@ internal object AgpConfiguratorUtils { project.pluginManager.withPlugin("com.android.library", action) } + fun configureBuildConfigFieldsForLibraries(appProject: Project) { + appProject.rootProject.allprojects { subproject -> + subproject.pluginManager.withPlugin("com.android.library") { + subproject.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext -> + ext.buildFeatures.buildConfig = true + } + } + } + } + fun configureDevPorts(project: Project) { val devServerPort = project.properties["reactNativeDevServerPort"]?.toString() ?: DEFAULT_DEV_SERVER_PORT