Android C++ build fails with react-native-nitro-modules >= 0.33 — jhybridobject / javaobject type resolution errors
Description
When building a React Native Android app that depends on react-native-nitro-healthkit v1.0.0, the native C++ compilation fails if the project uses react-native-nitro-modules >= 0.33.x. The generated C++ stubs shipped in react-native-nitro-healthkit are incompatible with the newer fbjni API introduced in those versions.
Environment
react-native-nitro-healthkit: 1.0.0
react-native-nitro-modules: 0.35.9 (also fails with 0.33.x, 0.34.x)
react-native: 0.83.x
- Android build target: arm64-v8a
- Gradle: 9.3.1
Build Error
/home/runner/work/cherry-studio-app/cherry-studio-app/node_modules/react-native-nitro-healthkit/android/../nitrogen/generated/android/c++/JHybridHealthKitSpec.hpp:25:66: error: unknown type name 'jhybridobject'; did you mean 'JHybridObject::CxxPart::jhybridobject'?
25 | static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
| ^~~~~~~~~~~~~
| JHybridObject::CxxPart::jhybridobject
...
/home/runner/work/cherry-studio-app/cherry-studio-app/node_modules/react-native-nitro-healthkit/nitrogen/generated/android/c++/JHybridHealthKitSpec.hpp:46:56: error: no member named 'javaobject' in 'margelo::nitro::healthkit::JHybridHealthKitSpec'
46 | inline const jni::global_ref<JHybridHealthKitSpec::javaobject>& getJavaPart() const noexcept {
| ~~~~~~~~~~~~~~~~~~~~~~^
...
13 errors generated.
ninja: build stopped: subcommand failed.
Root Cause
The nitrogen/generated/android/c++/JHybridHealthKitSpec.hpp file was generated by an older version of nitrogen (the devDependencies field declares nitrogen: ^0.30.0 and react-native-nitro-modules: ^0.30.0). The generated stubs use:
jhybridobject (bare unqualified type) — in newer versions of facebook/fbjni shipped with react-native-nitro-modules >= 0.33, this type was moved/namespaced under JHybridObject::CxxPart::jhybridobject.
JHybridHealthKitSpec::javaobject — this member type is no longer available in the newer fbjni Hybrid class template.
However, the peerDependencies in package.json claims compatibility with "react-native-nitro-modules": ">=0.30.0", which falsely includes versions >= 0.33 that are incompatible with the pre-generated C++ code.
Additional Context
The GitHub repo kingstinct/react-native-healthkit (the older package name) has a related issue about this same jhybridobject API change: kingstinct/react-native-healthkit#302
That issue is specific to @kingstinct/react-native-healthkit but the same underlying Nitro Modules API change affects this package as well.
Suggested Fix
- Regenerate stubs: Re-run
nitrogen with a version compatible with the latest react-native-nitro-modules to generate updated C++ stubs that work with the new fbjni API.
- Update peer dependency: If a fix cannot be published immediately, constrain the peer dependency to
"react-native-nitro-modules": ">=0.30.0 <0.33" to prevent users from hitting this error.
Workaround
Users currently affected can downgrade react-native-nitro-modules to ~0.32.x or patch the generated C++ header to qualify jhybridobject as JHybridObject::CxxPart::jhybridobject and add using javaobject = ... aliases.
Android C++ build fails with
react-native-nitro-modules >= 0.33—jhybridobject/javaobjecttype resolution errorsDescription
When building a React Native Android app that depends on
react-native-nitro-healthkitv1.0.0, the native C++ compilation fails if the project usesreact-native-nitro-modules >= 0.33.x. The generated C++ stubs shipped inreact-native-nitro-healthkitare incompatible with the newer fbjni API introduced in those versions.Environment
react-native-nitro-healthkit: 1.0.0react-native-nitro-modules: 0.35.9 (also fails with 0.33.x, 0.34.x)react-native: 0.83.xBuild Error
Root Cause
The
nitrogen/generated/android/c++/JHybridHealthKitSpec.hppfile was generated by an older version ofnitrogen(thedevDependenciesfield declaresnitrogen: ^0.30.0andreact-native-nitro-modules: ^0.30.0). The generated stubs use:jhybridobject(bare unqualified type) — in newer versions offacebook/fbjnishipped withreact-native-nitro-modules >= 0.33, this type was moved/namespaced underJHybridObject::CxxPart::jhybridobject.JHybridHealthKitSpec::javaobject— this member type is no longer available in the newer fbjni Hybrid class template.However, the
peerDependenciesinpackage.jsonclaims compatibility with"react-native-nitro-modules": ">=0.30.0", which falsely includes versions >= 0.33 that are incompatible with the pre-generated C++ code.Additional Context
The GitHub repo
kingstinct/react-native-healthkit(the older package name) has a related issue about this samejhybridobjectAPI change: kingstinct/react-native-healthkit#302That issue is specific to
@kingstinct/react-native-healthkitbut the same underlying Nitro Modules API change affects this package as well.Suggested Fix
nitrogenwith a version compatible with the latestreact-native-nitro-modulesto generate updated C++ stubs that work with the new fbjni API."react-native-nitro-modules": ">=0.30.0 <0.33"to prevent users from hitting this error.Workaround
Users currently affected can downgrade
react-native-nitro-modulesto~0.32.xor patch the generated C++ header to qualifyjhybridobjectasJHybridObject::CxxPart::jhybridobjectand addusing javaobject = ...aliases.