From f2884a761becb94d7ab1bb515b9c6cbfdb24835d Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 14 Sep 2023 04:22:52 -0700 Subject: [PATCH] Make sure first Gradle Sync is downloading 3rd party deps (#39426) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39426 When opening the react-native repo in Android Studio the first time, users is missing 3rd party native dependencies, which gets downloaded during the first build. Here I'm hooking the Gradle sync step to the `preBuild` task that takes care of preparing the repo so that the whole build can succeeds (i.e. downloading and unzipping native deps, running codegen, preparing hermes/hermesc, etc.). Changelog: [Internal] [Changed] - Make sure first Gradle Sync is downloading 3rd party deps Reviewed By: cipolleschi Differential Revision: D49231058 fbshipit-source-id: 11a3d436550581f8a67a582f9fd325ad39486ddc --- packages/react-native/ReactAndroid/build.gradle | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/react-native/ReactAndroid/build.gradle b/packages/react-native/ReactAndroid/build.gradle index 39555f48e59ee8..bb60e11dd28347 100644 --- a/packages/react-native/ReactAndroid/build.gradle +++ b/packages/react-native/ReactAndroid/build.gradle @@ -392,6 +392,11 @@ task downloadNdkBuildDependencies { dependsOn(downloadGtest) } +task prepareKotlinBuildScriptModel { + // This task is run when Gradle Sync is running. + // We create it here so we can let it depend on preBuild inside the android{} +} + // As ReactAndroid builds from source, the codegen needs to be built before it can be invoked. // This is not the case for users of React Native, as we ship a compiled version of the codegen. final def buildCodegenCLITask = tasks.register('buildCodegenCLI', BuildCodegenCLITask) { @@ -609,6 +614,10 @@ android { preparePrefab ) generateCodegenSchemaFromJavaScript.dependsOn(buildCodegenCLITask) + prepareKotlinBuildScriptModel.dependsOn( + preBuild, + ":packages:react-native:ReactAndroid:hermes-engine:preBuild", + ) sourceSets.main { res.srcDirs = ["src/main/res/devsupport", "src/main/res/shell", "src/main/res/views/modal", "src/main/res/views/uimanager"]