fix: make sure native libs are loaded for RN >= 0.80#315
Conversation
cause: loadNativeLibs() in ReactNativeBrownfield.kt is a no-op for RN >= 0.80. All ReactNativeHostManager templates call loadReactNative(application) BEFORE ReactNativeBrownfield.initialize(), so when done through the recommended path the libs load. But loadNativeLibs() — called inside every initialize() overload — silently skips for RN >= 0.80. Any consumer using ReactNativeBrownfield.initialize() directly — with a custom ReactHost, custom packages list, or custom options — skipped native lib loading entirely. Without JNI_OnLoad firing, registerComponentDescriptorsFromEntryPoint and the DefaultTurboModuleManagerDelegate module providers were never assigned, leading to the SIGSEGV during Fabric initialization. ddc011c — moved SoLoader.init() from preloadReactNative() into initialize(application, rnHost, ...). Before this, SoLoader.init() was called inside preloadReactNative after creating the React context. It was consolidated into the initialize entry point. 9908b68 — added the RN_THRESHOLD_VERSION = "0.80.0" gate and removed SoLoader.init() + load() for RN ≥ 0.80, leaving those calls only for < 0.80. ReactNativeBrownfield.initialize() itself had no fallback for the RN ≥ 0.80 case. If anything bypasses ReactNativeHostManager — a custom ReactHost, a consumer calling initialize() directly, or the generated ReactNativeApplicationEntryPoint being unavailable — native libs are never loaded. That's the bug this fix addresses.
hurali97
left a comment
There was a problem hiding this comment.
If I understand correctly, the crash happens because the user does not call the loadReactNative in some integrations, so we are saying that we will do it for them if they do not follow the docs?
Since we are now using Reflection, we will need to ask the User to add this ReactNativeApplicationEntryPoint to their consumer-rules - so this is one extra step for them and we need to document it, see here
Also, let's get rid of RN <=80 support, only keep 80+ changes.
artus9033
left a comment
There was a problem hiding this comment.
LGTM after 1 comment, great job!
| Class.forName("com.facebook.react.ReactNativeApplicationEntryPoint") | ||
| val loadReactNativeMethod = reactNativeApplicationEntryPointClazz.getMethod( | ||
| "loadReactNative", | ||
| android.content.Context::class.java | ||
| ) | ||
| loadReactNativeMethod.invoke(null, application.applicationContext) |
There was a problem hiding this comment.
As we discussed, let's try to check which versions of RN expose this API and instead of reflection, try checking the version
There was a problem hiding this comment.
I also think we should drop RN <=80 support now, no point in maintaining a version outside of release support window.
There was a problem hiding this comment.
Agreed, if this is only for <= 0.80, I think we can drop it. Our compat matrix states >=0.83 for Brownfield v3.
There was a problem hiding this comment.
Summary
loadNativeLibs()inReactNativeBrownfield.ktis a no-op forRN >= 0.80. AllReactNativeHostManagertemplates callloadReactNative(application)BEFOREReactNativeBrownfield.initialize(), so when done through the recommended path the libs load. ButloadNativeLibs()— called inside everyinitialize()overload — silently skips forRN >= 0.80. Any consumer usingReactNativeBrownfield.initialize()directly — with a customReactHost, custom packages list, or custom options — skipped native lib loading entirely. WithoutJNI_OnLoadfiring,registerComponentDescriptorsFromEntryPointand theDefaultTurboModuleManagerDelegatemodule providers were never assigned, leading to theSIGSEGVduring Fabric initialization.ddc011c— movedSoLoader.init()frompreloadReactNative()intoinitialize(application, rnHost, ...). Before this,SoLoader.init()was called insidepreloadReactNativeafter creating the React context. It was consolidated into the initialize entry point.9908b68— added theRN_THRESHOLD_VERSION = "0.80.0"gate and removedSoLoader.init()+load()forRN ≥ 0.80, leaving those calls only for< 0.80.ReactNativeBrownfield.initialize()itself had no fallback for theRN ≥ 0.80case. If anything bypassesReactNativeHostManager— a customReactHost, a consumer callinginitialize()directly, or the generatedReactNativeApplicationEntryPointbeing unavailable — native libs are never loaded. That's the bug this fix addresses.Test plan
To genuinely reproduce the original crash we'd need one of:
59f472bconsumed by the reporter's enterprise applibreact_codegen_rnscreens.soNeither is practical to set up cleanly. The
SoLoader.init()not yet called crash the GH issue reporter produced is sufficient proof that the same class of bug exists — the fix prevents both the Java exception AND the conditions that led to the original native crash.