Skip to content

fix(android): prepare Nitro prefab headers before native clean#1327

Open
Phecda wants to merge 1 commit into
mrousavy:mainfrom
Phecda:fix/android-nitro-headers-before-native-clean
Open

fix(android): prepare Nitro prefab headers before native clean#1327
Phecda wants to merge 1 commit into
mrousavy:mainfrom
Phecda:fix/android-nitro-headers-before-native-clean

Conversation

@Phecda

@Phecda Phecda commented May 19, 2026

Copy link
Copy Markdown

Summary

Draft PR to discuss a narrow Android clean-ordering fix for react-native-nitro-modules.

react-native-nitro-modules publishes its Android prefab target with headers under:

android/build/headers/nitromodules

Those headers are produced by the Gradle prepareHeaders task. During native clean flows, clean can remove android/build/headers, then dependent Android projects may still run externalNativeBuildClean* and read the react-native-nitro-modules::NitroModules prefab target. At that point CMake can fail because the target's include directory no longer exists:

Imported target "react-native-nitro-modules::NitroModules" includes
non-existent path ".../react-native-nitro-modules/android/build/headers/nitromodules"

This patch keeps the scope limited to packages/react-native-nitro-modules:

  • prepareHeaders must run after this project's clean task when both are in the graph;
  • dependent Android projects' externalNativeBuildClean* tasks depend on prepareHeaders, so Nitro prefab headers exist before native clean reads the prefab metadata.

This intentionally targets native clean. It does not claim to be a complete fresh Gradle Sync fix.

Test plan

git diff --check

Result: passed.

Notes for review

The contribution guide requires bug fixes to include a test. This PR is opened as a draft because this behavior depends on a consumer Gradle task graph (externalNativeBuildClean* reading another project's prefab metadata after clean removes generated headers). I would like maintainer guidance on the preferred regression coverage for that scenario before requesting review.

Scope this change to react-native-nitro-modules Android prefab cleanup. Ensure prepareHeaders runs after clean and before dependent externalNativeBuildClean tasks so NitroModules prefab headers exist when native clean reads the target metadata.
@vercel

vercel Bot commented May 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
nitro-docs Skipped Skipped May 19, 2026 11:11am

Request Review

@mrousavy mrousavy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I really appreciate some help on this end, as the Gradle/CMake build setup is still a bit weird for cleaning/detecting changes.

def prepareHeadersTask = tasks.named("prepareHeaders")

prepareHeadersTask.configure {
mustRunAfter(tasks.named("clean"))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause prepareHeaders to always do a clean* before too?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this only keeps prepareHeaders run after clean if they are both planned to run. prepareHeaders wont trigger a clean itself.
Ref: mustRunAfter

@Phecda

Phecda commented May 19, 2026

Copy link
Copy Markdown
Author

FYI: I use this patch with RN#56886 , but they dont depend on each other.

@Phecda Phecda marked this pull request as ready for review May 19, 2026 14:07
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