Skip to content

Commit

Permalink
Do not use rootProject directly in Gradle scripts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cortinico authored and facebook-github-bot committed Apr 7, 2022
1 parent f8d7e0a commit b2bc5aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def AAR_OUTPUT_URL = "file://${projectDir}/../android"
def customDownloadsDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File("$buildDir/downloads")
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
def reactNativeRootDir = projectDir.parent

// You need to have following folders in this directory:
// - boost_1_63_0
Expand Down Expand Up @@ -277,7 +278,7 @@ android {

externalNativeBuild {
cmake {
arguments "-DREACT_COMMON_DIR=${rootProject.projectDir}/ReactCommon",
arguments "-DREACT_COMMON_DIR=${reactNativeRootDir}/ReactCommon",
"-DREACT_ANDROID_DIR=$projectDir",
"-DANDROID_STL=c++_shared",
"-DANDROID_TOOLCHAIN=clang",
Expand Down
9 changes: 5 additions & 4 deletions ReactAndroid/hermes-engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ plugins {
id("maven-publish")
}

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

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

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

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

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

0 comments on commit b2bc5aa

Please sign in to comment.