Skip to content

Commit b2bc5aa

Browse files
cortinicofacebook-github-bot
authored andcommitted
Do not use rootProject directly in Gradle scripts
Summary: While testing with the RN Nightly versions, I realized we pushed two changes recently that are not working fine with the gradle setup of our users. That's becuase we're referencing the `rootProject` directly. `rootProject` should never be used directly as it resolves to: - The root of the git repo of `react-native` when building the RN project (so `./ReactCommon` exists there). - The /android folder of users' project when building an app that uses RN (so `./ReactCommon` does not exists there). Changelog: [Android] [Fixed] - Do not use `rootProject` directly in Gradle scripts Reviewed By: sshic Differential Revision: D35444967 fbshipit-source-id: be0508480a08224302168804b6feb52fd604d8db
1 parent f8d7e0a commit b2bc5aa

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

ReactAndroid/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def AAR_OUTPUT_URL = "file://${projectDir}/../android"
2929
def customDownloadsDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
3030
def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File("$buildDir/downloads")
3131
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
32+
def reactNativeRootDir = projectDir.parent
3233

3334
// You need to have following folders in this directory:
3435
// - boost_1_63_0
@@ -277,7 +278,7 @@ android {
277278

278279
externalNativeBuild {
279280
cmake {
280-
arguments "-DREACT_COMMON_DIR=${rootProject.projectDir}/ReactCommon",
281+
arguments "-DREACT_COMMON_DIR=${reactNativeRootDir}/ReactCommon",
281282
"-DREACT_ANDROID_DIR=$projectDir",
282283
"-DANDROID_STL=c++_shared",
283284
"-DANDROID_TOOLCHAIN=clang",

ReactAndroid/hermes-engine/build.gradle

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ plugins {
1313
id("maven-publish")
1414
}
1515

16+
def reactNativeRootDir = project(':ReactAndroid').projectDir.parent;
1617
def customDownloadDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
17-
def downloadsDir = customDownloadDir ? new File(customDownloadDir) : rootProject.file("sdks/download")
18+
def downloadsDir = customDownloadDir ? new File(customDownloadDir) : new File(reactNativeRootDir, "sdks/download")
1819

1920
// By default we are going to download and unzip hermes inside the /sdks/hermes folder
2021
// but you can provide an override for where the hermes source code is located.
2122
def overrideHermesDir = System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR") != null
22-
def hermesDir = System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR") ?: rootProject.file("sdks/hermes")
23+
def hermesDir = System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR") ?: new File(reactNativeRootDir, "sdks/hermes")
2324

2425
def hermesVersion = "main"
25-
def hermesVersionFile = rootProject.file("sdks/.hermesversion")
26+
def hermesVersionFile = new File(reactNativeRootDir, "sdks/.hermesversion")
2627
if (hermesVersionFile.exists()) {
2728
hermesVersion = hermesVersionFile.text
2829
}
@@ -34,7 +35,7 @@ def prefabHeadersDir = new File("$buildDir/prefab-headers")
3435
def skipPrefabPublishing = System.getenv("REACT_NATIVE_HERMES_SKIP_PREFAB") != null
3536

3637
// We inject the JSI directory used inside the Hermes build with the -DJSI_DIR config.
37-
def jsiDir = rootProject.file("ReactCommon/jsi")
38+
def jsiDir = new File(reactNativeRootDir, "ReactCommon/jsi")
3839

3940
// The .aar is placed inside the ./android folder at the top level.
4041
// There it will be placed alongside the React Android .aar

0 commit comments

Comments
 (0)