OneSignal / OneSignal-Unity-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Unity app with OneSignal. https://onesignal.com
Other
222 stars 61 forks source link

[Bug]: com.onesignal.OSUtils.getTargetSdkVersion #566

Closed shefich closed 1 year ago

shefich commented 1 year ago

What happened?

The latest version of SDK gives such error if "OneSignal.Default.PromptForPushNotificationsWithUserResponse();" used in code Happens only on Android 13 devices. Need to have use case of this code in tutorial.

Steps to reproduce?

1. Install OneSignal 3.0.7
2. Use "OneSignal.Default.PromptForPushNotificationsWithUserResponse();" in Start() method.

What did you expect to happen?

No crash expected

Unity version

2021.2.15

OneSignal Unity SDK version

3.0.7

Platform

Android

Relevant log output

`Fatal Exception: java.lang.Error
FATAL EXCEPTION [main] Unity version : 2020.3.42f1 Device model : Google Redfin 64-bit only Device fingerprint: google/redfin_64/redfin:13/TP1A.220624.014/8819323:userdebug/dev-keys Build Type : Release Scripting Backend : IL2CPP ABI : arm64-v8a Strip Engine Code : true

Caused by java.lang.NoClassDefFoundError
com.onesignal.NotificationPermissionController
com.onesignal.OneSignal.onAppFocus (OneSignal.java:1410)
com.onesignal.OSFocusHandler.startOnFocusWork (OSFocusHandler.kt:54)
com.onesignal.ActivityLifecycleHandler.handleFocus (ActivityLifecycleHandler.java:191)
com.onesignal.ActivityLifecycleHandler.onActivityResumed (ActivityLifecycleHandler.java:95)
com.onesignal.ActivityLifecycleListener.onActivityResumed (ActivityLifecycleListener.java:91)
android.app.Application.dispatchActivityResumed (Application.java:431)

com.android.internal.os.ZygoteInit.main (ZygoteInit.java:936)

Caused by java.lang.ExceptionInInitializerError
com.onesignal.OneSignal.promptForPushNotifications (OneSignal.java:2864)
com.unity3d.player.UnityPlayer.nativeRender
com.unity3d.player.UnityPlayer.access$300
com.unity3d.player.UnityPlayer$e$1.handleMessage (Unknown Source:95)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loopOnce (Looper.java:201)
android.os.Looper.loop (Looper.java:288)
com.unity3d.player.UnityPlayer$e.run (Unknown Source:20)

Caused by java.lang.NullPointerException
Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
com.onesignal.OSUtils.getTargetSdkVersion (OSUtils.java:490)
com.onesignal.NotificationPermissionController. (NotificationPermissionController.kt:48)
com.onesignal.OneSignal.promptForPushNotifications (OneSignal.java:2864)
com.unity3d.player.UnityPlayer.nativeRender
com.unity3d.player.UnityPlayer.access$300
com.unity3d.player.UnityPlayer$e$1.handleMessage (Unknown Source:95)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loopOnce (Looper.java:201)
android.os.Looper.loop (Looper.java:288)
com.unity3d.player.UnityPlayer$e.run (Unknown Source:20)`

Code of Conduct

brismithers commented 1 year ago

@shefich From the log message you provided, it looks like the SDK has not yet been initialized. Can you please confirm that OneSignal.Default.Initialize has been called prior to your call to OneSignal.Default.PromptForPushNotificationsWithUserResponse();?

Thanks!

brismithers commented 1 year ago

It looks like this is duplicating #565

brismithers commented 1 year ago

Hi @shefich can you confirm if the above suggestion resolved your issue? Thanks!

shefich commented 1 year ago

Hi @brismithers I think it is solved based on your suggestion.

brismithers commented 1 year ago

awesome glad we could help @shefich!