OneSignal-Android-SDK
OneSignal-Android-SDK copied to clipboard
[Bug]: OneSignalService.onPostAppCreated java.lang.NullPointerException
What happened?
Since que upgraded from OneSignal 4.X.X to OneSignal 5.0.4 we started to see the following error on Firebase crashlytics.
Caused by java.lang.NullPointerException: at com.onesignal.core.internal.application.impl.ApplicationService.getAppContext(ApplicationService.kt:39) at com.onesignal.core.internal.preferences.impl.PreferencesService.getSharedPrefsByName(PreferencesService.kt:234) at com.onesignal.core.internal.preferences.impl.PreferencesService.get(PreferencesService.kt:134) at com.onesignal.core.internal.preferences.impl.PreferencesService.getString(PreferencesService.kt:42) at com.onesignal.common.modeling.ModelStore.load(ModelStore.kt:165) at com.onesignal.common.modeling.SimpleModelStore.
(SimpleModelStore.kt:23) at com.onesignal.core.internal.config.ConfigModelStore. (ConfigModelStore.kt:8) at java.lang.reflect.Constructor.newInstance0(Constructor.java) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at com.onesignal.common.services.ServiceRegistrationReflection.resolve(ServiceRegistration.kt:89) at com.onesignal.common.services.ServiceProvider.getServiceOrNull(ServiceProvider.kt:79) at com.onesignal.common.services.ServiceProvider.getService(ServiceProvider.kt:67) at com.onesignal.common.services.ServiceProvider.getService$com_onesignal_core(ServiceProvider.kt:39) at com.onesignal.internal.OneSignalImp.initWithContext(OneSignalImp.kt:188) at com.onesignal.OneSignal.initWithContext(OneSignal.kt:135)
This happens on the start up and in a variety of devices and Android Versions.
Steps to reproduce?
Upgrade to OneSignal 5.0.4 aande wait for the errors on Firebase crashlytics.
We didn't find a way to reproduce it in our test devices.
What did you expect to happen?
No errors on FIrebase crashlytics
OneSignal Android SDK version
5.0.4
Android version
13, 12, 11, 10, 9
Specific Android models
No response
Relevant log output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Thank you for reaching out! We'll investigate this.
Hi we just updated to the latest of the sdk 5.0.5 and the problem remains.
this is a fresh log
Hello just for your info we just updated to the latest versión 5.1.0 and the error remains.
This is the top error in our app :(
Hello we released a new version with the 5.1.1 and the error persists (But we reduced ARN thx!).
This is a log with the last version
Can you give me some feedback @jennantilla please is the most frequent error on our app.
Regards
Hello? any news regarding this @jennantilla.
Hi @albertoderodrigo, Thank you for following up with your updates and attaching new stacktraces.
I am noting for ourselves to investigate that the stacktraces show two scenarios that triggered the getAppContext
NPE:
com.onesignal.core.internal.preferences.impl.PreferencesService.getSharedPrefsByName(PreferencesService.kt:234)
com.onesignal.core.internal.device.impl.DeviceService.packageInstalledAndEnabled(DeviceService.kt:106)
We have no updates yet.
Hi @nan-li,
We can add more logs or traces at the moment that the exception is raised. What information could help you?
Hi @albertoderodrigo,
I have looked at your logs again, and they all arise from your app's method onPostAppCreated
calling OneSignal.initWithContext
. Can you share what kind of context you are passing?
at com.onesignal.OneSignal.initWithContext(OneSignal.kt:135)
at io.socialgamesonline.slotcom.features.OneSignalService.onPostAppCreated(OneSignalService.kt:38)
Also, do you see any crashes that originate from other sources that are not from you calilng the method, such as BroadcastReceivers, etc?
Hi @nan-li.
We use the getApplicationContext from the custom Application. This is provided on the onCreate event.
I just checked a lot of this crashes an all are originated from the same source. Has your initWithContext
checks if context is null then the only possibility that i see is that sometimes ApplicationService init has not been called before the trying to acquire the context from it.
We have a fix that will lower and possibly fix all crashes related to this null
Context
being thrown from initWithContext
issue in the OneSignal-Android-SDK 5.1.6 release.
@albertoderodrigo if you continue to seeing this issue after updating to 5.1.6 please let us know the new percentages of crashes the new stack traces.
Hi @jkasten2, we just releases a hotfix with your update. On Monday I will let you know if it has disappeared or not.
Thx
Hi @jkasten2, the error disappeared!! Thx!
@albertoderodrigo That is awesome to hear! Appreciate you reporting back the results!