Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Crash "RuntimeException: Could not invoke OneSignal.hasNotificationPermission" #1681

Open
2 of 3 tasks
audrius-sav opened this issue Apr 5, 2024 · 4 comments
Open
2 of 3 tasks

Comments

@audrius-sav
Copy link

What happened?

The latest OneSignal RN SDK v5.1.0 causes a RuntimeException and crashes the app when calling getPermissionAsync() in some Android devices according to our Sentry and Google Play crash analytics. Stack trace that's posted below suggests initWithContext is the culprit, but I'm sure we followed the OneSignal SDK setup thoroughly, and definitely call OneSignal.initialize with our appId on app startup. Interestingly, I cannot reproduce this crash on my physical OnePlus 8T device or Android 13 emulator, but some of my colleagues can, e.g. with Samsung Galaxy A14.
Not sure about iOS.

Steps to reproduce?

Not sure how to reproduce, happens on some Android devices, e.g. Samsung Galaxy A14, Galaxy Tab A7, Galaxy A03, Moto E22, Galaxy A01, Redmi Note 8 and a lot others.

What did you expect to happen?

I expect the app to not crash when OneSignal.getPermissionAsync() is called.

React Native OneSignal SDK version

Release 5.1.0

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

java.lang.Exception: Must call 'initWithContext' before use
    at com.onesignal.internal.OneSignalImp.getNotifications(OneSignalImp.kt:96)
    at com.onesignal.OneSignal.getNotifications(OneSignal.kt:62)
    at com.onesignal.rnonesignalandroid.RNOneSignal.hasNotificationPermission(RNOneSignal.java:460)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:149)
    at com.facebook.jni.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:234)
    at java.lang.Thread.run(Thread.java:1012)
java.lang.reflect.InvocationTargetException: null
    at java.lang.reflect.Method.invoke(Method.java)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:149)
    at com.facebook.jni.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:234)
    at java.lang.Thread.run(Thread.java:1012)
java.lang.RuntimeException: Could not invoke OneSignal.hasNotificationPermission
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:381)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:149)
    at com.facebook.jni.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:234)
    at java.lang.Thread.run(Thread.java:1012)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@audrius-sav
Copy link
Author

Probably an issue on our side, didn't call initialize() in some cases. But still should it really cause a Runtime Exception and crash the app?

@imiguez
Copy link

imiguez commented May 24, 2024

I changed the initialize parameter from OneSignal.initialize(Constants.expoConfig.extra.oneSignalAppId) to OneSignal.initialize(process.env.EXPO_PUBLIC_ONE_SIGNAL_APP_ID) and the error disappeared.

@123dma
Copy link

123dma commented Aug 13, 2024

same error here

@JohnGeorgiadis
Copy link

Same here with

    "react-native-onesignal": "^5.2.5",
    "onesignal-expo-plugin": "^2.0.3",

it affects mostly samsung devices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants