Fix crash for setEventEmitterCallback NoSuchMethodError on API lvl 26 (#48606)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48606

Fixes https://github.com/facebook/react-native/issues/48009

The app is currently crashing on Android API lvl 26 attempting to invoke the method
`setEventEmitterCallback` which is defined inside BaseJavaModule.

I'm not entirely sure why this is happening only for API lvl 26, but I've verified
that by having the method protected, this doesn't happen anymore.

The visibility is consistent with the field `mEventEmitterCallback` which is also
protected and accessed to codegen. So let's keep them aligned for consistency.

Changelog:
[Android] [Fixed] - Fix crash for setEventEmitterCallback NoSuchMethodError on API lvl 26

Reviewed By: cipolleschi

Differential Revision: D68018506

fbshipit-source-id: 87eda718c9774b584abdf771eaad5833d452a1ea
This commit is contained in:
Nicola Corti
2025-01-10 07:56:17 -08:00
committed by Facebook GitHub Bot
parent 4c7c836ebf
commit 7dcbc799eb
2 changed files with 2 additions and 1 deletions
@@ -608,6 +608,7 @@ public abstract class com/facebook/react/bridge/BaseJavaModule : com/facebook/re
protected final fun getReactApplicationContextIfActiveOrWarn ()Lcom/facebook/react/bridge/ReactApplicationContext;
public fun initialize ()V
public fun invalidate ()V
protected fun setEventEmitterCallback (Lcom/facebook/react/bridge/CxxCallbackImpl;)V
}
public abstract interface class com/facebook/react/bridge/BridgeReactContext$RCTDeviceEventEmitter : com/facebook/react/bridge/JavaScriptModule {
@@ -134,7 +134,7 @@ public abstract class BaseJavaModule implements NativeModule {
}
@DoNotStrip
private final void setEventEmitterCallback(CxxCallbackImpl eventEmitterCallback) {
protected void setEventEmitterCallback(CxxCallbackImpl eventEmitterCallback) {
mEventEmitterCallback = eventEmitterCallback;
}
}