fix(android): create transport HybridObject on JS thread (fix ClassNotFound)#8
Merged
Merged
Conversation
…oader) Runtime ClassNotFoundException for com.margelo.nitro.ecr17.HybridEcr17Transport on every command: createHybridObject's JNI FindClass resolves against the current thread's class loader, and the Nitro worker thread (attached via ThreadScope) has the SYSTEM class loader, which can't see app classes. Fix: run ensureInit() (the createHybridObject) in configure(), which executes on the JS thread where the app class loader is available. fbjni caches the resolved jclass globally, so subsequent method calls from worker threads succeed (they only need a JNIEnv, provided by the ThreadScope guards). Found by running the example app on a device. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- LESSON: fix now-stale notes (client include is HybridEcr17Client.hpp; createHybridObject downcast is dynamic_pointer_cast on the JS thread). - AGENTS: add a consolidated "Nitro Android native integration (JNI)" rule group (impl-header naming, dynamic_pointer_cast, react-native.config.js, ThreadScope, createHybridObject on the JS thread) — all reproducible only by running the app. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
java.lang.ClassNotFoundException: com.margelo.nitro.ecr17.HybridEcr17Transportthrown on every command when running the example app on a device.Root cause:
createHybridObjectdoes a JNIFindClass, which resolves against the current thread's class loader. The previous JNI fix attaches Nitro worker threads viaThreadScope, but an attached worker thread gets the system class loader (visible in the error'sDexPathList[... /system/lib64 ...]), which can't see app/library classes.Fix: run
ensureInit()(thecreateHybridObject) insideconfigure(), which executes on the JS thread where the app class loader is present. fbjni caches the resolvedjclassglobally, so later method calls from worker threads work (they only need aJNIEnv, supplied by the existingThreadScopeguards).Verification
Test plan
🤖 Generated with Claude Code