Skip to content

Commit 63ca55b

Browse files
cortinicofacebook-github-bot
authored andcommitted
Unblock build-from-source on nightlies (#39634)
Summary: Pull Request resolved: #39634 Running build from source as suggested here: https://reactnative.dev/contributing/how-to-build-from-source is currently broken for nightly versions (and for 0.73). This fixes it by: - Fixing the import of the Gradle Version Catalog - Actually adding the Gradle version catalog to the NPM package - Fixing how the build Codegen CLI task is invoked for build-from-source - Updating the search directories for codegenDir/reactNativeDir from build-from-source Changelog: [Internal] [Fixed] - Unblock build-from-source on nightlies Reviewed By: cipolleschi Differential Revision: D49562595 fbshipit-source-id: 9594b7d947569d41c461a7e8287d3ae68fb87b98
1 parent babbc3e commit 63ca55b

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract class PrivateReactExtension @Inject constructor(project: Project) {
3030
.directoryProperty()
3131
.convention(
3232
// This is the default for the project root if the users hasn't specified anything.
33-
// If the project is called "react-native-github"
33+
// If the project is called "react-native-github" or "react-native-build-from-source"
3434
// - We're inside the Github Repo -> root is defined by RN Tester (so no default
3535
// needed)
3636
// - We're inside an includedBuild as we're performing a build from source
@@ -39,7 +39,8 @@ abstract class PrivateReactExtension @Inject constructor(project: Project) {
3939
// - We're inside a user project, so inside the ./android folder. Default should be
4040
// ../
4141
// User can always override this default by setting a `root =` inside the template.
42-
if (project.rootProject.name == "react-native-github") {
42+
if (project.rootProject.name == "react-native-github" ||
43+
project.rootProject.name == "react-native-build-from-source") {
4344
project.rootProject.layout.projectDirectory.dir("../../")
4445
} else {
4546
project.rootProject.layout.projectDirectory.dir("../")

packages/react-native/ReactAndroid/build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ task prepareKotlinBuildScriptModel {
392392
final def buildCodegenCLITask = tasks.register('buildCodegenCLI', BuildCodegenCLITask) {
393393
it.codegenDir.set(file("$rootDir/node_modules/@react-native/codegen"))
394394
it.bashWindowsHome.set(project.findProperty("react.internal.windowsBashPath"))
395+
it.onlyIf {
396+
// For build from source scenario, we don't need to build the codegen at all.
397+
rootProject.name != "react-native-build-from-source"
398+
}
395399
}
396400

397401
/**
@@ -790,6 +794,16 @@ react {
790794
jsRootDir = file("../Libraries")
791795
}
792796

797+
// For build from source, we need to override the privateReact extension.
798+
// This is neeeded as the build-from-source won't have a com.android.application
799+
// module to apply the plugin to, so it's codegenDir and reactNativeDir won't be evaluated.
800+
if (rootProject.name == "react-native-build-from-source") {
801+
privateReact {
802+
codegenDir = file("$rootDir/../@react-native/codegen")
803+
reactNativeDir = file("$rootDir")
804+
}
805+
}
806+
793807
kotlin {
794808
jvmToolchain(17)
795809
}

packages/react-native/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"cli.js",
3636
"flow",
3737
"gradle.properties",
38+
"gradle/libs.versions.toml",
3839
"index.js",
3940
"interface.js",
4041
"jest-preset.js",

packages/react-native/settings.gradle.kts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ pluginManagement {
1919
}
2020
}
2121

22-
dependencyResolutionManagement {
23-
versionCatalogs { create("libs") { from(files("gradle/libs.versions.toml")) } }
24-
}
25-
26-
rootProject.name = "react-native-github"
22+
rootProject.name = "react-native-build-from-source"
2723

2824
include(":packages:react-native:ReactAndroid")
2925

0 commit comments

Comments
 (0)