From b9dad7fc0c040813ca173bc531a8cd2d9a8ace1c Mon Sep 17 00:00:00 2001 From: Alexander Eggers <7427545+AlexanderEggers@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:31:53 -0700 Subject: [PATCH] fix: prevent error when react extension was already created (#43694) Summary: Currently the react-native-gradle-plugin does not allow the "react" plugin extension to already exist when running its apply block. I had a use-case where I wanted to create a new gradle plugin which would take care of applying the react plugin including setting some of its options. Without the change in this PR, this would currently turn into a build failure. ## Changelog: [ANDROID] [FIXED] - prevent error when the "react" extension was already created by another gradle plugin Pull Request resolved: https://github.com/facebook/react-native/pull/43694 Reviewed By: rshest Differential Revision: D55478611 Pulled By: zeyap fbshipit-source-id: cc743a99cb72ed315d21c52597efd5ee92a3be62 --- .../src/main/kotlin/com/facebook/react/ReactPlugin.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 2c5bea4099c..a06841d76d8 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 @@ -38,7 +38,10 @@ import org.gradle.internal.jvm.Jvm class ReactPlugin : Plugin { override fun apply(project: Project) { checkJvmVersion(project) - val extension = project.extensions.create("react", ReactExtension::class.java, project) + val extension = + project.rootProject.extensions.findByType(ReactExtension::class.java) + ?: project.rootProject.extensions.create("react", ReactExtension::class.java, project) + checkIfNewArchFlagIsSet(project, extension) // We register a private extension on the rootProject so that project wide configs