From c7d969f31b1d584f593dfcbf119765b5efa4bc95 Mon Sep 17 00:00:00 2001 From: UNIDY2002 Date: Tue, 17 Oct 2023 05:46:53 -0700 Subject: [PATCH] Configure Java toolchains only when executing App configuration (#40757) Summary: Fix https://github.com/facebook/react-native/issues/40560 ## Changelog: [ANDROID] [FIXED] - Ensure that `configureJavaToolChains` is only executed once during configuration Pull Request resolved: https://github.com/facebook/react-native/pull/40757 Test Plan: - Create a fresh `react-native@0.73.0-rc.1` project - Install `react-native-webview` - Apply [this patch](https://github.com/react-native-webview/react-native-webview/pull/3175/files) for `react-native-webview` (caused by another issue https://github.com/facebook/react-native/issues/40559) - Edit `android/gradle.properties` and set `newArchEnabled` to true - Build application - (Expected) Application fail to build - Apply this PR - (Expected) Application build successfully **Additional explanation:** According to the implementation of `configureJavaToolChains`, all the subprojects (both the app and the libraries) will have their toolchains setup in one execution of the method. Therefore, it is okay for the method to be invoked only when configuring the plugin for the app. On the other hand, invoking the method for more than one time will cause the issue stated in https://github.com/facebook/react-native/issues/40560. Reviewed By: cipolleschi Differential Revision: D50361871 Pulled By: cortinico fbshipit-source-id: bd5e18df97988122788d0482dba954e517a0cb5c --- .../src/main/kotlin/com/facebook/react/ReactPlugin.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 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 4c41e6a2373..f64aa685382 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 @@ -70,6 +70,7 @@ class ReactPlugin : Plugin { configureBuildConfigFieldsForApp(project, extension) configureDevPorts(project) configureBackwardCompatibilityReactMap(project) + configureJavaToolChains(project) project.extensions.getByType(AndroidComponentsExtension::class.java).apply { onVariants(selector().all()) { variant -> @@ -80,13 +81,10 @@ class ReactPlugin : Plugin { } // Library Only Configuration + configureBuildConfigFieldsForLibraries(project) project.pluginManager.withPlugin("com.android.library") { configureCodegen(project, extension, rootExtension, isLibrary = true) } - - // Library and App Configurations - configureJavaToolChains(project) - configureBuildConfigFieldsForLibraries(project) } private fun checkJvmVersion(project: Project) {