zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.73k stars 2.05k forks source link

Fatal Exception: java.lang.NoSuchMethodError: No virtual method addReactInstanceEventListener(Lcom/facebook/react/ReactInstanceEventListener;) #2338

Closed janilamppu closed 4 months ago

janilamppu commented 1 year ago

After updating targetSdkVersion from 30 to 31 we started getting a following crash on our app that points to this library. The crash is random and happens on all Android versions. Using the latest version of the lib.

Does this seem familiar to anyone? Can't find any references to a similar issue.

Fatal Exception: 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:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8741) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

ashishmangukiya commented 1 year ago

@janilamppu I have already raise a bug on this. You can check this https://github.com/zo0r/react-native-push-notification/issues/2337

janilamppu commented 1 year ago

Thank you @ashishmangukiya - that might be the same case however I didn't recognize it at first. We don't use action buttons though and this started happening after the change of targetSdkVersion. Hopefully there will be a fix or a workaround.

ilya-gritsenko commented 1 year ago

Got exactly the same error yesterday, although we didn't have any app deployments in months, so not sure what was the trigger.

aotaduy commented 1 year ago

Same error after updating the targetSdkVersion to 31 and not using notifications with buttons.

java.lang.NoSuchMethodError: No virtual method addReactInstanceEventListener(Lcom/facebook/react/ReactInstanceEventListener;)V in class Lcom/facebook/react/p; or its super classes (declaration of 'com.facebook.react.p' appears in base.apk) at com.dieam.reactnativepushnotification.modules.RNReceivedMessageHandler$1.run(RNReceivedMessageHandler:145) at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) at android.app.ActivityThread.main(ActivityThread.java:7425) at java.lang.reflect.Method.invoke(Method.java:-2) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

abdelav commented 1 year ago

for anyone looking for a possible solution, this is how I solve the issue on my end:

that works for me, hope it helps.

AndersonSchmidt commented 1 year ago

for anyone looking for a possible solution, this is how I solve the issue on my end:

  • got to node_modules/react-native-push-notification/android/build.gradle
  • make implementation 'com.facebook.react:react-native:+' to match with your exact react-native version in my case is implementation 'com.facebook.react:react-native:0.67.4'
  • then just patch the package using https://www.npmjs.com/package/patch-package

that works for me, hope it helps.

This works!

ilya-gritsenko commented 1 year ago

for anyone looking for a possible solution, this is how I solve the issue on my end:

  • got to node_modules/react-native-push-notification/android/build.gradle
  • make implementation 'com.facebook.react:react-native:+' to match with your exact react-native version in my case is implementation 'com.facebook.react:react-native:0.67.4'
  • then just patch the package using https://www.npmjs.com/package/patch-package

that works for me, hope it helps.

The culprit is actually jcenter repo, it fetches version 0.71.0-rc.0 from here - https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml

I applied similar fix, but instead of targeting specific version I simply commented out jcenter and mavenCentral (just in case, so that same issue doesn't happen if mavenCentral repo will suddenly get newer version of react-native) repos. This way you make sure that only your local react-native version from node_modules is used.

github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.