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) + } + } } }