Skip to content

Android 构建失败:react-native-nitro-healthkit 与 react-native-nitro-modules >= 0.33 的 fbjni API 不兼容 #476

Description

@ook826092-cloud

Android C++ build fails with react-native-nitro-modules >= 0.33jhybridobject / 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

  1. 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.
  2. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions