Skip to content

fix(android): update nitrogen-generated code to CxxPart/JavaPart pattern#169

Open
hamdij0maa wants to merge 1 commit intorive-app:mainfrom
hamdij0maa:fix/update-nitrogen-android-cxxpart-pattern
Open

fix(android): update nitrogen-generated code to CxxPart/JavaPart pattern#169
hamdij0maa wants to merge 1 commit intorive-app:mainfrom
hamdij0maa:fix/update-nitrogen-android-cxxpart-pattern

Conversation

@hamdij0maa
Copy link

@hamdij0maa hamdij0maa commented Mar 5, 2026

Summary

  • Updates all nitrogen-generated Android code (68 files) to use the newer Nitro Modules API with CxxPart/JavaPart inner classes instead of the legacy HybridClass pattern
  • Fixes Android build compatibility with recent versions of react-native-nitro-modules (0.35.0)
  • Adds registerAllNatives() entry point and deprecates the old initialize() function

Changes

Kotlin (20 files)

All HybridXxxSpec.kt files updated:

  • Removed manual HybridData/initHybrid()/updateNative() boilerplate
  • Added CxxPart inner class and createCxxPart() override

C++ Headers (20 files)

All JHybridXxxSpec.hpp files updated:

  • Migrated from jni::HybridClass<JHybridXxxSpec, JHybridObject> to JavaPart/CxxPart struct pattern
  • Updated constructor to accept JavaPart reference
  • Removed getExternalMemorySize(), equals(), dispose(), toString() (now handled by base class)
  • Changed _javaPart type from javaobject to JavaPart

C++ Implementations (20 files)

All JHybridXxxSpec.cpp files updated:

  • Added JavaPart::getJHybridXxxSpec() factory method
  • Added CxxPart::initHybrid(), CxxPart::createHybridObject(), CxxPart::registerNatives()
  • Replaced javaClassStatic()-> with _javaPart->javaClassStatic()->

Other files (8 files)

  • JVariant_* and JResolvedReferencedAsset: Updated ::javaobject references to ::JavaPart
  • JHybridRiveViewStateUpdater: Updated view reference pattern for new API
  • riveOnLoad.hpp/cpp: Added registerAllNatives(), deprecate initialize(), added Impl factory structs
  • cpp-adapter.cpp: Use facebook::jni::initialize with registerAllNatives()

Context

The current nitrogen-generated code uses an older Nitro Modules pattern that is incompatible with react-native-nitro-modules v0.22+. The new CxxPart/JavaPart pattern is the current standard used by the nitrogen code generator. This can alternatively be fixed by re-running the nitrogen code generator against the current version.

Test plan

  • Verify Android build succeeds
  • Test Rive animations render correctly on Android
  • Verify iOS is unaffected (no iOS changes)
  • Test ViewModel data binding functionality

Update the nitrogen-generated Android code to use the newer Nitro Modules
API with CxxPart/JavaPart inner classes instead of the legacy HybridClass
pattern. This fixes compatibility with recent versions of react-native-nitro-modules (0.22+).

Changes across 68 files:
- All HybridSpec.kt files: Replace manual HybridData/initHybrid with CxxPart inner class
- All JHybridSpec.hpp files: Migrate from HybridClass to JavaPart/CxxPart structs
- All JHybridSpec.cpp files: Update JNI implementations, replace javaClassStatic() calls
- JVariant/JResolvedReferencedAsset: Update javaobject refs to JavaPart
- JHybridRiveViewStateUpdater: Update view references for new pattern
- riveOnLoad: Add registerAllNatives(), deprecate initialize(), add Impl factories
- cpp-adapter.cpp: Use facebook::jni::initialize with registerAllNatives
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.

1 participant