customerio / customerio-android

This is the official Customer.io SDK for Android.
MIT License
13 stars 9 forks source link

Crash when rich push with image is received while the app is closed #168

Closed tfcporciuncula closed 1 year ago

tfcporciuncula commented 1 year ago

SDK version: 3.1.1

Environment: Development or Production

Are logs available? Yes but there are no logs from CIO, only the stacktrace:

FATAL EXCEPTION: Firebase-Messaging-Intent-Handle
Process: de.climatelabs.planetwild.debug, PID: 20818
java.lang.IllegalStateException: CustomerIO.Builder::build() must be called before obtaining CustomerIO instance
  at io.customer.sdk.CustomerIO$Companion.instance(CustomerIO.kt:119)
  at io.customer.messagingpush.CustomerIOFirebaseMessagingService$Companion.getDiGraph(CustomerIOFirebaseMessagingService.kt:14)
  at io.customer.messagingpush.CustomerIOFirebaseMessagingService$Companion.handleMessageReceived(CustomerIOFirebaseMessagingService.kt:56)
  at io.customer.messagingpush.CustomerIOFirebaseMessagingService$Companion.handleMessageReceived$default(CustomerIOFirebaseMessagingService.kt:51)
  at io.customer.messagingpush.CustomerIOFirebaseMessagingService.onMessageReceived(CustomerIOFirebaseMessagingService.kt:65)
  at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@22.0.0:13)
  at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@22.0.0:8)
  at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@22.0.0:3)
  at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@22.0.0:3)
  at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:firebase-messaging@@22.0.0:1)
  at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(Unknown Source:6)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
  at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@18.1.0:2)
  at java.lang.Thread.run(Thread.java:1012)

Describe the bug App process crashes and notification isn't rendered when we send a rich push with an image while the app process is dead.

To Reproduce

Expected behavior Notification is rendered and process doesn't crash.

Screenshots N/A

Additional context The error message may make it seem like we're not properly setting up the SDK, but we are. Everything is working and we're able to receive notifications without images while the app process is dead (and everything works fine while the app is open). But as soon as we add images, this happens, so I believe there's an issue on the SDK side.

I've found this issue on a Pixel 4 running Android 13 but I also tried on an emulator running Android 11 and I was also able to reproduce it there, so it doesn't really seem to be device or Android version specific.

tfcporciuncula commented 1 year ago

It turns out the issue was indeed on our end. We were initializing CIO lightly asynchronously on app start, and for some reason the only issue we encountered was this one. It seems to work fine if we initialize it completely synchronously, though.

I think it might be worth it to emphasize this in the documentation since I believe many other peeps might have the same idea of offloading this kind of initialization to a background thread so it doesn't compete with our app start. I'm keeping the issue open just in case you still want to take a look at this, but otherwise feel free to close it.

Shahroz16 commented 1 year ago

Hey @tfcporciuncula, thank you point this out, we will update it in the docs. But you are correct, we need SDK to be initialized before any of the methods are to be performed.

Closing this with an action on my end, feel free to reach out if you have more questions.