From bd94a13c5db739d8d6bfdd6fe210b750a9491446 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 24 Jul 2025 05:23:38 -0700 Subject: [PATCH] RNGP - Fix a race condition with codegen libraries missing sources (#52803) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52803 I've just realized that our build suffer from a race condition. Specifically libraries codegen needs to be executed before the app starts the evaluating CMake files. Otherwise this could lead to a lot of missing files or folders. Changelog: [Android] [Fixed] - **rngp:** Fix a race condition with codegen libraries missing sources Reviewed By: huntie Differential Revision: D78886347 fbshipit-source-id: f59c201d2eab651bc4a08cf5a795acd379d18186 --- .../com/facebook/react/ReactRootProjectPlugin.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt index 5f232cd0e58..f8aee12b822 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt @@ -26,5 +26,21 @@ class ReactRootProjectPlugin : Plugin { it.evaluationDependsOn(":app") } } + // We need to make sure that `:app:preBuild` task depends on all other subprojects' preBuild + // tasks. This is necessary in order to have all the codegen generated code before the CMake + // configuration build kicks in. + project.gradle.projectsEvaluated { + val appProject = project.rootProject.subprojects.find { it.name == "app" } + val appPreBuild = appProject?.tasks?.findByName("preBuild") + if (appPreBuild != null) { + // Find all other subprojects' preBuild tasks + val otherPreBuildTasks = + project.rootProject.subprojects + .filter { it != appProject } + .mapNotNull { it.tasks.findByName("preBuild") } + // Make :app:preBuild depend on all others + appPreBuild.dependsOn(otherPreBuildTasks) + } + } } }