react-native-push-notification
react-native-push-notification copied to clipboard
NoSuchMethodError: No virtual method addReactInstanceEventListener
If an react native application with version <0.68.0 uses react-native-push-notification library, it will crash on Android. It will crash only at first install, because RNPushNotificationListenerService::onNewToken runs once.
Crash log:
java.lang.NoSuchMethodError: No virtual method addReactInstanceEventListener(Lcom/facebook/react/ReactInstanceEventListener;)V in class Lcom/facebook/react/ReactInstanceManager; or its super classes (declaration of 'com.facebook.react.ReactInstanceManager' appears in base.apk)
at com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService$1.run(RNPushNotificationListenerService.java:52)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Reason:
in build.gradle file (module :react-native-push-notification):
-
implementation 'com.facebook.react:react-native:+'
- Library uses later react-native version (0.71.0-rc.0 in my case) than my application which is 0.67.2.
- In reactnativepushnotification/modules/RNPushNotificationListenerService.java file:
-
mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {})
- this line tries to invoke addReactInstanceEventListener function with ReactInstanceEventListener interface which is inside ReactInstanceManager class. But addReactInstanceEventListener method has changed at react-native 0.68.0-rc.0 and ReactInstanceEventListener written in a seperate file. (commit: https://github.com/facebook/react-native/commit/ce74aa4ed335d4c36ce722d47937b582045e05c4)
After react-native 0.68.0-rc.0:
- addReactInstanceEventListener function accepts com.facebook.react.ReactInstanceEventListener object, not ReactInstanceManager.ReactInstanceEventListener.
- com.facebook.react.ReactInstanceEventListener is not available in previous versions.
Solutions:
- Change library react-native version from + to your application react-native version.
implementation 'com.facebook.react:react-native:+'
=>implementation 'com.facebook.react:react-native:0.67.2'
- Update application react-native version to later than 0.68.0-rc.0
I'm seeing the same? issue with
-
react-native
0.65.2
-
react-native-push-notification
^7.3.1
NoSuchMethodError: No virtual method addReactInstanceEventListener(Lcom/facebook/react/ReactInstanceEventListener;)V in class Lcom/facebook/react/ReactInstanceManager; or its super classes (declaration of 'com.facebook.react.ReactInstanceManager' appears in base.apk)
I'm seeing the same? issue with
react-native
0.65.2
react-native-push-notification
^7.3.1
NoSuchMethodError: No virtual method addReactInstanceEventListener(Lcom/facebook/react/ReactInstanceEventListener;)V in class Lcom/facebook/react/ReactInstanceManager; or its super classes (declaration of 'com.facebook.react.ReactInstanceManager' appears in base.apk)
Same thing in firebase crashlytics
Update to react-native: 0.68.7
and react-native-push-notification: 8.1.1
resolved the issue, as suggested by the author.