Skip to content

android: patch RN settings.gradle.kts /tmp projectDir for Windows - #387

Open
kraenhansen wants to merge 2 commits into
kh/adopt-static-h-node-apifrom
claude/windows-gradle9-projectdir
Open

android: patch RN settings.gradle.kts /tmp projectDir for Windows#387
kraenhansen wants to merge 2 commits into
kh/adopt-static-h-node-apifrom
claude/windows-gradle9-projectdir

Conversation

@kraenhansen

@kraenhansen kraenhansen commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Targets the kh/adopt-static-h-node-api branch (PR #372). Follow-up to #386, which greened ubuntu + macOS but left windows-latest red on a different cause.

Root cause

After #386 fixed the Project.exec() removal, the Windows Gradle build got further and both gradle.test.ts cases failed at configuration time:

Configuring project ':packages:react-native' without an existing directory is not allowed.
The configured projectDirectory '...\react-native@0.87...\node_modules\react-native\tmp' does not exist

This is upstream React Native, not our code. RN's own settings.gradle.kts (used for build-from-source composite builds, which this project requires) declares the intermediate container projects with a throwaway dir:

// Since Gradle 9.0, all the projects in the path must have an existing folder.
project(":packages").projectDir = file("/tmp")
project(":packages:react-native").projectDir = file("/tmp")

/tmp exists on the posix CI hosts, so ubuntu/macOS pass. On Windows /tmp is not absolute, so Gradle resolves it to a non-existent <react-native>\tmp, and Gradle 9 hard-errors on a missing projectDirectory — failing before any task runs.

Fix

A pnpm patch on our pinned RN nightly, replacing file("/tmp") with file(System.getProperty("java.io.tmpdir", "/tmp")) — the JVM temp dir, which is /tmp on posix and %TEMP% on Windows and always exists.

Files:

  • patches/react-native@0.87.0-nightly-20260529-88857d22f.patch
  • pnpm-workspace.yaml (patchedDependencies entry)
  • pnpm-lock.yaml

Scope and tradeoffs — read before merging

This patch is deliberately workspace-only. It is not distributed to consumers of react-native-node-api.

patchedDependencies in pnpm-workspace.yaml applies to installs in this repo only. It is not part of the published packages/host tarball, and it does not apply to a user's app even if they also use pnpm. So merging this fixes our CI, and nothing else.

What that means for users, concretely:

  • react-native-node-api requires building React Native from source on Android (we need Hermes patched with Node-API — see docs/ANDROID.md). That is exactly the code path this RN bug breaks.
  • Therefore, on Windows hosts, a user on an RN version that still hardcodes /tmp cannot build their Android app at all — it fails at Gradle configuration time, before any of our code runs.
  • macOS and Linux hosts are unaffected (/tmp exists there), so this is a Windows-only user-facing gap.
  • There is no workaround we can ship. The failure is in RN's settings.gradle.kts, evaluated during Gradle's settings phase of the composite build. Our Gradle plugin and our npm package are both loaded too late to intervene. The only real fixes are the upstream change, or the user applying an equivalent patch in their own app.

Why not distribute it anyway: we'd have to ask every consumer to add a patch for a specific RN version string, which breaks the moment they bump RN, and it would only ever have helped the subset of users who (a) are on Windows and (b) pin the same RN nightly we do. The upstream fix is already merged; carrying a distributable patch would be maintenance for a window that's closing on its own.

Removal gate

The upstream fix is merged: facebook/react-native#57706, landed on main as 908872a6 on 2026-07-28.

It landed after the 0.87 branch cut, so 0.87-stable does not carry it — 0.87.0 final (currently at rc.4) will still be broken on Windows unless someone cherry-picks it. Revert this patch once we pin a react-native that actually contains 908872a6:

  • a nightly built from main on/after 2026-07-29 (our current pin is 0.87.0-nightly-20260529, which predates it), or
  • the first stable line branched after it (0.88+), or
  • a 0.87.x that cherry-picks it.

Bumping the pinned nightly past 2026-07-29 would drop the patch outright — but that's a much larger change to land on top of the static_h work in #372, so it's intentionally left out of this PR.

The same condition is recorded as a comment inside the patch itself, so whoever next touches it doesn't have to find this PR.

Test plan

  • CI on this branch: Unit tests (windows-latest) green; ubuntu/macOS green.

The native Android build isn't runnable on the worker this was authored on, so cross-platform behaviour is verified by CI rather than locally.


Generated by Claude Code

The Windows unit-test lane failed configuring the React Native build-from-
source composite build:

    Configuring project ':packages:react-native' without an existing directory
    is not allowed. The configured projectDirectory '...\react-native\tmp'
    does not exist

React Native's own settings.gradle.kts declares the intermediate container
projects :packages and :packages:react-native with projectDir = file("/tmp"),
purely to satisfy Gradle 9's rule that every project in a path have an existing
folder. "/tmp" exists on the posix CI hosts but on Windows it is not an
absolute path, so Gradle resolves it to a non-existent <react-native>\tmp and
the build fails before any task runs. This is why only windows-latest was red
while ubuntu and macOS passed.

Add a pnpm patch replacing file("/tmp") with
file(System.getProperty("java.io.tmpdir", "/tmp")): the JVM temp dir is "/tmp"
on posix and %TEMP% on Windows, both of which always exist. Remove the patch
once React Native stops hardcoding "/tmp" upstream.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TVfanKvtyfSsoMgZv3DJtY
meta-codesync Bot pushed a commit to react/react-native that referenced this pull request Jul 28, 2026
…ed /tmp (#57706)

Summary:
`packages/react-native/settings.gradle.kts` declares the intermediate container projects `:packages` and `:packages:react-native` with `projectDir = file("/tmp")`, to satisfy Gradle 9's requirement that every project in a path have an existing folder. `/tmp` exists on posix hosts, but on Windows it is not an absolute path, so Gradle resolves it to a non-existent `<rootDir>\tmp` and build-from-source fails at configuration time:

    Configuring project ':packages:react-native' without an existing directory
    is not allowed.

Use `System.getProperty("java.io.tmpdir", "/tmp")` instead — the JVM temp dir, which is `/tmp` on posix and `%TEMP%` on Windows, and always exists.

## Changelog

[ANDROID] [FIXED] - Use the JVM temp dir instead of a hardcoded `/tmp` for the build-from-source container project dirs, fixing Gradle configuration on Windows

Pull Request resolved: #57706

Test Plan:
- posix: the resolved dir is unchanged (`/tmp`); build-from-source configures as before.
- Windows: resolves to an existing temp dir, so `includeBuild(../node_modules/react-native)`
  configures successfully instead of erroring.
- Downstream evidence: this exact change greened the `windows-latest` Gradle lane in
  callstackincubator/react-native-node-api#387.

Reviewed By: christophpurrer

Differential Revision: D113816859

Pulled By: Abbondanzo

fbshipit-source-id: 9846dadab9012369dcab26aa05ea3297633acf9f
The upstream fix landed on react-native main as 908872a6 (2026-07-28,
react/react-native#57706), after the 0.87 branch cut — so 0.87-stable
does not carry it. Record that in the patch comment so the removal gate is
a concrete react-native version rather than "once upstream fixes it".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants