react-native-onesignal icon indicating copy to clipboard operation
react-native-onesignal copied to clipboard

[Bug]: OSUtils.java:490 Could not invoke OneSignal.promptForPushNotificationsWithUserResponse

Open invyctus92 opened this issue 2 years ago • 25 comments

What happened?

I got this error report from my analytics bugsnag: here is the device info: manufacturer Google model Pixel 4a osName android osVersion 13 runtimeVersions { "reactNativeJsEngine": "hermes", "reactNative": "0.70.4", "androidApiLevel": "33", "osBuild": "TP1A.221005.002" }

Steps to reproduce?

Call
OneSignal.promptForPushNotificationsWithUserResponse(false, response => {
      console.log('Prompt response:', response);
});

What did you expect to happen?

The popup should appear to ask for permissions for notifications

React Native OneSignal SDK version

4.4.1

Which platform(s) are affected?

  • [ ] iOS
  • [X] Android

Relevant log output

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(NativeRunnable.java:-2)
        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:201)
        at android.os.Looper.loop(Looper.java:288)
        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(Method.java:-2)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
        at com.facebook.jni.NativeRunnable.run(NativeRunnable.java:-2)
        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:201)
        at android.os.Looper.loop(Looper.java:288)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
        at java.lang.Thread.run(Thread.java:1012)

Caused by: java.lang.ExceptionInInitializerError
        at com.onesignal.OneSignal.promptForPushNotifications(OneSignal.java:2864)
        at com.geektime.rnonesignalandroid.RNOneSignal.promptForPushNotificationsWithUserResponse(RNOneSignal.java:473)
        at java.lang.reflect.Method.invoke(Method.java:-2)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
        at com.facebook.jni.NativeRunnable.run(NativeRunnable.java:-2)
        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:201)
        at android.os.Looper.loop(Looper.java:288)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
        at java.lang.Thread.run(Thread.java:1012)

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)
        at com.onesignal.OneSignal.promptForPushNotifications(OneSignal.java:2864)
        at com.geektime.rnonesignalandroid.RNOneSignal.promptForPushNotificationsWithUserResponse(RNOneSignal.java:473)
        at java.lang.reflect.Method.invoke(Method.java:-2)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
        at com.facebook.jni.NativeRunnable.run(NativeRunnable.java:-2)
        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:201)
        at android.os.Looper.loop(Looper.java:288)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
        at java.lang.Thread.run(Thread.java:1012)

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

invyctus92 avatar Nov 07 '22 15:11 invyctus92

@invyctus92 Thanks for reporting with the fullstack trace. Can you let us know what event you are calling OneSignal.promptForPushNotificationsWithUserResponse() from?

What are the percentage of users are getting this crash?

Are you able to reproduce the crash? If so, what is the step-by-step to reproduce it?

jkasten2 avatar Dec 01 '22 07:12 jkasten2

same situation, I'm calling that function as it is in the documentation. in a separate file.

see logs from Google crash details:

Exception 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.react.bridge.queue.NativeRunnable.run (NativeRunnable.java)
  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:226)
  at android.os.Looper.loop (Looper.java:313)
  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 (Method.java)
  at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
Caused by java.lang.ExceptionInInitializerError:
  at com.onesignal.OneSignal.promptForPushNotifications (OneSignal.java:2864)
  at com.geektime.rnonesignalandroid.RNOneSignal.promptForPushNotificationsWithUserResponse (RNOneSignal.java:473)
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)

beqramo avatar Dec 08 '22 16:12 beqramo

@jkasten2 Hi, Any update on it? I'm getting many crashes on it. Here are some insights: Error occurs on android 13 image

beqramo avatar Dec 20 '22 19:12 beqramo

Hello! My phone (Samsung Galaxy A51, Android 13) autoupdated today (details about patch -- https://doc.samsungmobile.com/SM-A515F/SER/doc.html) and my react-native app started crashing.

2022-12-23 21:15:15.618  6408-6460  AndroidRuntime          pid-6408                             E  FATAL EXCEPTION: mqt_native_modules
                                                                                                    Process: ru.azbykamebeli, PID: 6408
                                                                                                    java.lang.RuntimeException: Could not invoke OneSignal.promptForPushNotificationsWithUserResponse
                                                                                                    	at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:192)
                                                                                                    	at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:147)
                                                                                                    	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(Unknown Source:0)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:226)
                                                                                                    	at android.os.Looper.loop(Looper.java:313)
                                                                                                    	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37)
                                                                                                    	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(Unknown Source:148)
                                                                                                    	at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:147) 
                                                                                                    	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(Unknown Source:0) 
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:226) 
                                                                                                    	at android.os.Looper.loop(Looper.java:313) 
                                                                                                    	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37) 
                                                                                                    	at java.lang.Thread.run(Thread.java:1012) 
                                                                                                    Caused by: java.lang.ExceptionInInitializerError
                                                                                                    	at com.onesignal.c3.G1(Unknown Source:0)
                                                                                                    	at com.geektime.rnonesignalandroid.RNOneSignal.promptForPushNotificationsWithUserResponse(Unknown Source:11)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    	at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:148) 
                                                                                                    	at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:147) 
                                                                                                    	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(Unknown Source:0) 
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:226) 
                                                                                                    	at android.os.Looper.loop(Looper.java:313) 
                                                                                                    	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37) 
                                                                                                    	at java.lang.Thread.run(Thread.java:1012) 
                                                                                                    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.o(Unknown Source:0)
                                                                                                    	at com.onesignal.l0.<clinit>(Unknown Source:27)
                                                                                                    	at com.onesignal.c3.G1(Unknown Source:0) 
                                                                                                    	at com.geektime.rnonesignalandroid.RNOneSignal.promptForPushNotificationsWithUserResponse(Unknown Source:11) 
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    	at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:148) 
                                                                                                    	at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:147) 
                                                                                                    	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(Unknown Source:0) 
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:226) 
                                                                                                    	at android.os.Looper.loop(Looper.java:313) 
                                                                                                    	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37) 
                                                                                                    	at java.lang.Thread.run(Thread.java:1012) 

Dependencies:

"react-native": "^0.70.6",
"react-native-onesignal": "^4.5.0",

Dimous avatar Dec 23 '22 11:12 Dimous

It is only crashes in release mode. Should I tweak proguard rules or something? Please help ASAP or I'm gonna get fired 😂

Dimous avatar Dec 27 '22 09:12 Dimous

any update on this issue?

cloudtenlabs avatar Jan 09 '23 04:01 cloudtenlabs

Any update on this? Facing the same issue - only on the release build.

@Dimous have you found a solution or we've been/gonna be fired? :)))

alex-yplabs avatar Jan 11 '23 08:01 alex-yplabs

Getting the same crash for my application too. And the app crashes only on Samsung devices.

iamrohitagg avatar Jan 28 '23 05:01 iamrohitagg

In the end, I fixed my issue by removing the code that was prompting programmatically the dialog to give notification permission, and I enabled that prompt using the in-app messages from OneSignal (the Push Permission Prompt one).

alex-yplabs avatar Jan 31 '23 20:01 alex-yplabs

@alex-yplabs Hi I have the same issue can you please provide a snippet example of your solution? thanks

ah584d avatar Feb 14 '23 12:02 ah584d

@alex-yplabs Hi I have the same issue can you please provide a snippet example of your solution? thanks

Hey!

It's not code per se. I just removed "OneSignal.promptForPushNotificationsWithUserResponse()" and I have used the In-App Message for notification prompt to actually prompt for push notifications (on the One Signal dashboard)

https://documentation.onesignal.com/docs/in-app-quickstart

alex-yplabs avatar Feb 14 '23 12:02 alex-yplabs

Same issue here, with Android devices only "react-native": "0.64.2", "react-native-onesignal": "^4.3.1",

MursiDirect avatar Mar 05 '23 23:03 MursiDirect

same issue in my emulator. "react-native": "0.70.5", [EDIT] => UPDATE to "0.70.7", "react-native-onesignal": "^4.5.0",

hotaryuzaki avatar Mar 16 '23 11:03 hotaryuzaki

i solve this with PermissionsAndroid from RN core

hotaryuzaki avatar Mar 17 '23 07:03 hotaryuzaki

i solve this with PermissionsAndroid from RN core

can you elaborate please? does it means that you still used the original snippet from from the doc + something else related to android permission? can you post your snippet? thanks

ah584d avatar Mar 17 '23 09:03 ah584d

i solve this with PermissionsAndroid from RN core

can you elaborate please? does it means that you still used the original snippet from from the doc + something else related to android permission? can you post your snippet? thanks

i dont use @alex-yplabs solution because In-App-Message is limited for free user. so i use PermissionsAndroid from react-native like here

await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);

hotaryuzaki avatar Mar 17 '23 10:03 hotaryuzaki

Same issue here.. affecting 11%: one1

Exception 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 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:226) at android.os.Looper.loop (Looper.java:313) 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 at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372) Caused by java.lang.ExceptionInInitializerError: at com.onesignal.OneSignal.promptForPushNotifications (OneSignal.java:2864) at com.geektime.rnonesignalandroid.RNOneSignal.promptForPushNotificationsWithUserResponse (RNOneSignal.java:473) 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)

hkanizawa avatar May 01 '23 12:05 hkanizawa

Does anyone have an update on this ?

We are experiencing the same issue with latest RN version (0.71.6) and target SDK set to 33.

john-llama avatar Jun 12 '23 14:06 john-llama

We are also having this issue. Target SDK is set to 33.

augustovicente avatar Jul 17 '23 19:07 augustovicente

in our case, there's no crash in the os logs, the permission dialog shows up but then the app gets stuck, it just hangs, buttons in the dialog do nothing i also added PERMISSIONS.POST_NOTIFICATIONS to the manifest, didn't make a difference it works normally on ios

jbrodriguez avatar Jul 24 '23 15:07 jbrodriguez

Any solution?

Android 13

"react-native": "0.72.4" "react-native-onesignal": "4.5.1"

android/build.gradle

buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33

alekaka avatar Aug 22 '23 20:08 alekaka

I am on react-native: 0.70.8, expo: ~47.0.14, react-native-onesignal: 4.5.1, and targetSDK 33

Still happens for people with android version 13 and above..

Any solution? Will upgrading the react-native-onesignal to 5.0.3 help?

danklad avatar Nov 27 '23 08:11 danklad

Facing same issue on Android 13 for Samsung devices in release mode:

package.json

"react": "18.2.0", "react-native": "0.71.6", "@sentry/react-native": "^5.15.1", "@sentry/wizard": "1.0.6", "react-native-onesignal": "^4.5.1",

android/build.gradle

buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33

mwaqarshahid avatar Jan 15 '24 12:01 mwaqarshahid

Hi folks,

Facing same issue on following versions:

"react": "17.0.2", "react-native": "0.68.6", "@react-native-firebase/crashlytics": "^12.4.0",

And I can't use PERMISSIONS.POST_NOTIFICATIONS because this POST_NOTIFICATION permission was not present react-native's versions below 0.70

Any suggestions in this case?

uasghar-smile avatar Jan 29 '24 20:01 uasghar-smile

Hi folks,

Facing same issue on following versions:

"react": "17.0.2", "react-native": "0.68.6", "@react-native-firebase/crashlytics": "^12.4.0",

And I can't use PERMISSIONS.POST_NOTIFICATIONS because this POST_NOTIFICATION permission was not present react-native's versions below 0.70

Any suggestions in this case?

update react native version to 0.70+ 🤣 and add: await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);

TrustDec avatar Feb 28 '24 06:02 TrustDec