fix: CMake not finding headers during Gradle Sync on a fresh install
Adds android/build/headers to the published files list in package.json to fix an error during Gradle Sync -> CMake.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| nitro-docs | ⬜️ Skipped (Inspect) | Mar 18, 2025 0:06am |
This is generated code by Android/Gradle. That should not be part of the npm package - I think. This should be built by the library consumer.
Do you disagree?
This is generated code by Android/Gradle. That should not be part of the npm package - I think. This should be built by the library consumer.
Do you disagree?
I agree that this is generated by Android/Gradle.
In build.gradle we copy headers files from ./android/src/main/cpp and ./cpp/ into the android/build/headers.
https://github.com/mrousavy/nitro/blob/ca86d9d296fe2e2fb76c6a4f0087adbb967172fa/packages/react-native-nitro-modules/android/build.gradle#L159-L165
The prefab config in build.gradle currently only allows a single header directory path, so if we want to have the header files split up as is, we'll have to rely on Gradle to copy and add them to the prefab.
This should be built by the library consumer.
The problem is that the shipped prefab is pointing to android/build/headers, therefore it throws an error on Gradle Sync, because it's not in the published files.
I agree this isn't 100% clean so we can either:
- copy over the header files somewhere else
- go with this approach (and optionally add the gradle sync command to the
prepublish/preparescript?)
Can't we use the headers from their original source (node_modules/react-native-nitro-modules/cpp/** and ........./android/**)?
That way we don't need to copy headers at all?
Also - which issue does this exactly fix?
Can't we use the headers from their original source (
node_modules/react-native-nitro-modules/cpp/**and........./android/**)?
As described above, the prefab.headers config in build.gradle only supports a single directory, not multiple.
Also - which issue does this exactly fix?
This one: (only on a clean install before the app was built)
You won't see this in the Nitro example, because react-native-nitro-modules is linked locally there. This is also reproducible in a fresh RN78 app (npx @react-native-community/cli@latest init) with a local Nitro module (npx nitro-codegen init)
ok, makes sense. then let's add a prepareHeaders command to the prepublish npm script
@mrousavy updated the scripts
can we not just make the prepareHeaders task dependent on a gradle sync? instead of a build
can we not just make the prepareHeaders task dependent on a gradle sync? instead of a build
@mrousavy Unfortunately you cannot attach any task/script during or before Gradle Sync (in the configure phase). Just tested it out and you cannot run any methods like from(), into(), etc. there.. I also tried copying the files in CMakeLists.txt, but that won't work either.
The problem is really, that the prefab expects the headers to be in that location, but the are not (yet) at the time of Gradle Sync. The prefab headers setting expects a single directory, so we cannot just replace it with the original header directories either.
I think running the copy script on prepublishOnly will be our only possibility, if we want to ensure, that the header files are present during NPM publish.
@mrousavy how should we proceed with this?
@mrousavy do you think we should fix this error with this hacky workaround or just ignore the error during Gradle Sync?
Seems there is no update in the Google IssueTracker issue around allowing multiple prefab.header directories to be defined, which would holistically fix this issue
closing since I don't think we should ship this. thanks tho