From b2e6a37e5bd32ebd2412d7464ee04dcbfd9612eb Mon Sep 17 00:00:00 2001 From: Blake Friedman Date: Thu, 13 Jun 2024 04:51:20 -0700 Subject: [PATCH] configure to build from source (#44920) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44920 Configure helloworld to build from source, using a combination of our [How to Build from Source](https://reactnative.dev/contributing/how-to-build-from-source#update-your-project-to-build-from-source) guide, as well as using rn-tester's config as a guide. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D58287748 fbshipit-source-id: 836b09416f4da4087fbdea4476d29cd226157914 --- packages/helloworld/android/app/build.gradle | 2 +- packages/helloworld/android/settings.gradle | 10 +++++++++- packages/react-native/ReactAndroid/build.gradle.kts | 10 +++++++++- packages/react-native/build.gradle.kts | 2 ++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/helloworld/android/app/build.gradle b/packages/helloworld/android/app/build.gradle index 557a871cce..bc4df63bfb 100644 --- a/packages/helloworld/android/app/build.gradle +++ b/packages/helloworld/android/app/build.gradle @@ -23,7 +23,7 @@ react { // The folder where the react-native NPM package is. Default is ../node_modules/react-native reactNativeDir = file("../../../react-native") // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen - codegenDir = file("../../../react-native-codegen") + codegenDir = file("$rootDir/node_modules/@react-native/codegen") // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js, // but now points to our simplified bundle wrapper. cliFile = file("../../scripts/bundle.js") diff --git a/packages/helloworld/android/settings.gradle b/packages/helloworld/android/settings.gradle index e80fcd06cf..6da9a43763 100644 --- a/packages/helloworld/android/settings.gradle +++ b/packages/helloworld/android/settings.gradle @@ -6,10 +6,18 @@ */ // Autolinking has now moved into the React Native Gradle Plugin -pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") } +pluginManagement { includeBuild("../../react-native-gradle-plugin") } plugins { id("com.facebook.react.settings") } extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } rootProject.name = 'HelloWorld' include ':app' includeBuild('../../react-native-gradle-plugin') +includeBuild('../../react-native') { + dependencySubstitution { + substitute(module("com.facebook.react:react-android")).using(project(":packages:react-native:ReactAndroid")) + substitute(module("com.facebook.react:react-native")).using(project(":packages:react-native:ReactAndroid")) + substitute(module("com.facebook.react:hermes-android")).using(project(":packages:react-native:ReactAndroid:hermes-engine")) + substitute(module("com.facebook.react:hermes-engine")).using(project(":packages:react-native:ReactAndroid:hermes-engine")) + } + } diff --git a/packages/react-native/ReactAndroid/build.gradle.kts b/packages/react-native/ReactAndroid/build.gradle.kts index c1598daa13..76d41a679a 100644 --- a/packages/react-native/ReactAndroid/build.gradle.kts +++ b/packages/react-native/ReactAndroid/build.gradle.kts @@ -794,7 +794,15 @@ react { // module to apply the plugin to, so it's codegenDir and reactNativeDir won't be evaluated. if (rootProject.name == "react-native-build-from-source") { rootProject.extensions.getByType(PrivateReactExtension::class.java).apply { - codegenDir = file("$rootDir/../@react-native/codegen") + // We try to guess where codegen lives. Generally is inside + // node_modules/@react-native/codegen. If the file is not existing, we + // fallback to ../react-native-codegen (used for hello-world app). + codegenDir = + if (file("$rootDir/../@react-native/codegen").exists()) { + file("$rootDir/../@react-native/codegen") + } else { + file("$rootDir/../react-native-codegen") + } reactNativeDir = file("$rootDir") } } diff --git a/packages/react-native/build.gradle.kts b/packages/react-native/build.gradle.kts index 5d7f54b975..2667e535a5 100644 --- a/packages/react-native/build.gradle.kts +++ b/packages/react-native/build.gradle.kts @@ -16,3 +16,5 @@ plugins { alias(libs.plugins.download) apply false alias(libs.plugins.kotlin.android) apply false } + +buildscript { dependencies { classpath("com.facebook.react:react-native-gradle-plugin") } }