-
Notifications
You must be signed in to change notification settings - Fork 25.1k
java.lang.RuntimeException: Could not invoke OneSignal.promptForPushNotificationsWithUserResponse #37055
Description
Description
Hello, I am using webview with react-native, along with onesignal and google ads. I have started experiencing an error more frequently, although it doesn't happen all the time. I haven't been able to find a solution for it, so I wanted to open a discussion about it. After this error occurs, the application stays in the background and can only be opened with a few persistent attempts. However, this leads to user loss, especially for new users. Thank you in advance for your help.
java.lang.RuntimeException: Could not invoke OneSignal.promptForPushNotificationsWithUserResponse at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383) at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188) at com.facebook.jni.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) at android.os.Looper.loopOnce(Looper.java:211) at android.os.Looper.loop(Looper.java:300) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228) at java.lang.Thread.run(Thread.java:1012) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372) ... 9 more Caused by: java.lang.ExceptionInInitializerError at com.onesignal.OneSignal.promptForPushNotifications(OneSignal.java:2864) at com.geektime.rnonesignalandroid.RNOneSignal.promptForPushNotificationsWithUserResponse(RNOneSignal.java:473) ... 11 more Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference at com.onesignal.OSUtils.getTargetSdkVersion(OSUtils.java:490) at com.onesignal.NotificationPermissionController.<clinit>(NotificationPermissionController.kt:48) ... 13 more
React Native Version
0.71.4
Output of npx react-native info
Directory: D:\apps
Android SDK: Not Found
Windows SDK:
AllowAllTrustedApps: Disabled
IDEs:
Android Studio: AI-213.7172.25.2113.9123335
Visual Studio: Not Found
Languages:
Java: 17.0.5 - C:\Program Files\Common Files\Oracle\Java\javapath\javac.EXE
npmPackages:
@react-native-community/cli: ^11.0.0 => 11.0.0
react: 18.2.0 => 18.2.0
react-native: 0.71.4 => 0.71.4
react-native-windows: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
It may occur when the application is first installed or later.
Snack, code example, screenshot, or link to a repository
`java.lang.RuntimeException: Could not invoke OneSignal.promptForPushNotificationsWithUserResponse
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)