crisp-im / crisp-sdk-android

:package: Crisp Android SDK, add a chat in any Android app and communicate with your users.
https://docs.crisp.chat/guides/chatbox-sdks/android-sdk/
Other
56 stars 17 forks source link

2.0.1beta2: app crashes when swiping down the chat screen #175

Closed gekylafas closed 2 weeks ago

gekylafas commented 3 months ago

In our app we open the chat screen using the following code

startActivity(Intent(context, ChatActivity::class.java))

Unfortunately, we have noticed that the app crashes if the user tries to close the chat screen (ChatActivity) not by pressing the "X" button but by swiping the chat screen down. We got two distinct stack traces, depending on whether we called the code above from a Fragment or from an Activity:

Fatal Exception: java.lang.IllegalStateException: Fragment d{c1f92c} (11a31416-37f8-4d4e-b1fe-19110436c190) has not been attached yet.
       at androidx.fragment.app.Fragment.getChildFragmentManager(Fragment.java:1142)
       at im.crisp.client.internal.v.d.f(SourceFile:1)
       at im.crisp.client.internal.v.d.b(SourceFile:3)
       at im.crisp.client.internal.v.d.d(SourceFile:3)
       at im.crisp.client.internal.v.d.a(SourceFile:3)
       at im.crisp.client.internal.v.d$d.e(SourceFile:1)
       at im.crisp.client.internal.v.d$d.$r8$lambda$f5zzx9QQEmu9lrxeSnlZRKsE2xg()
       at im.crisp.client.internal.v.d$d$$ExternalSyntheticLambda3.run(D8$$SyntheticClass)
       at android.os.Handler.handleCallback(Handler.java:959)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at android.app.ActivityThread.main(ActivityThread.java:8501)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

and

Fatal Exception: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
       at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236)
       at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110)
       at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:176)
       at com.bumptech.glide.Glide.with(Glide.java:634)
       at im.crisp.client.internal.v.k.b(SourceFile:6)
       at im.crisp.client.internal.v.k.a(SourceFile:2)
       at im.crisp.client.internal.v.k$a.b(SourceFile:1)
       at im.crisp.client.internal.v.k$a.$r8$lambda$tDEkukCqoTsvxBfaU8EYMQxQXWA()
       at im.crisp.client.internal.v.k$a$$ExternalSyntheticLambda2.run(D8$$SyntheticClass)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:201)
       at android.os.Looper.loop(Looper.java:288)
       at android.app.ActivityThread.main(ActivityThread.java:7872)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Are we doing something wrong or is it a bug in the SDK? Is there a way to disable swipe down gesture in ChatActivity?

Doc1faux commented 3 months ago

Hi @gekylafas and thank you for your feedback.

At a first glance, you don't seem to do anything wrong. For the moment, the swipe down gesture cannot be disable, but it could be a feature later?

Do you only updated to 2.0.1beta2? Is there any other change in your code interacting with the Crisp SDK? From which version do you updated?

This is a strange crash because in the stacktraces you provided, it always starts with the equivalent of the Session has loaded event from the WebSocket and any following UI call is protected with a check if the fragment is still attached to its activity because both WebSocket and UI are running in separate threads, so it should never happen...

gekylafas commented 3 months ago

@Doc1faux Thanks for the prompt reply.

We didn't update Crisp SDK from a previous version, this is the initial addition of the SDK to our app. I tried with 2.0.0beta1 and it shows the same behavior too. Version 1.0.18 doesn't seem to support swipe down, so no crash there 🤷‍♂️ . Is that version considered OK to be used by an app or is it deprecated?

As for the crash itself, and provided there is something wrong with the SDK and not our app (which might as well be), I am willing to help you debug this (e.g. try snapshot versions etc).

Doc1faux commented 3 months ago

So you don't reproduce it in the latest v1, interesting... I'll be grateful for more insights on this crash as I do not reproduce it on my side, either on debug/release, minified or not and on emulator or device :/

On which device (brand, model) or emulator and on which Android version are you testing your app? Can you provide me (here or in private), a minimal project where you reproduce it?

v1.0.18 is not deprecated but you'll miss functionalities and bug/crash fixes in very specific cases, I let you browse our releases to see for yourself if you could downgrade to it while we're fixing this crash.

gekylafas commented 3 months ago

Well, I can't reproduce it in v1 because this only happens on swipe down and v1 doesn't support swipe down, from what I can tell. 🤷‍♂️

I can reproduce it in both emulators and my device, for debug builds (haven't tried for release).

About a minimal project reproducing it, I will try to come up with something...

Doc1faux commented 1 month ago

Hi @gekylafas, I just shipped the new 2.0.2beta3 release. I dived into your stacktraces and tried to fix this crash which seems to be due to Glide image loading occuring while the chatbox is closing. I used the closest context to the component Glide is loading into. Let me know if it works as I still not able to reproduce it :/

gekylafas commented 2 weeks ago

Well, 2.0.2beta3 did do something as the app crashes with a different stacktrace now:

java.lang.IllegalStateException: Fragment d{f251d35} (560fe239-86e6-46b3-8b25-c2034edc8e0b) has not been attached yet.
   at androidx.fragment.app.Fragment.getChildFragmentManager(Fragment.java:1142)
   at im.crisp.client.internal.v.d.f(SourceFile:1)
   at im.crisp.client.internal.v.d.b(SourceFile:3)
   at im.crisp.client.internal.v.d.d(SourceFile:3)
   at im.crisp.client.internal.v.d.a(SourceFile:3)
   at im.crisp.client.internal.v.d$d.e(SourceFile:1)
   at im.crisp.client.internal.v.d$d.$r8$lambda$f5zzx9QQEmu9lrxeSnlZRKsE2xg(Unknown Source:0)
   at im.crisp.client.internal.v.d$d$$ExternalSyntheticLambda3.run(D8$$SyntheticClass:0)
   at android.os.Handler.handleCallback(Handler.java:959)
   at android.os.Handler.dispatchMessage(Handler.java:100)
   at android.os.Looper.loopOnce(Looper.java:232)
   at android.os.Looper.loop(Looper.java:317)
   at android.app.ActivityThread.main(ActivityThread.java:8592)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

I am starting to suspect there is something about this particular app too that causes the crashes.

Doc1faux commented 2 weeks ago

Hello @gekylafas,

It seems to be the same stacktrace as the 1st you shared. I already fixed the one about Glide (the 2nd you shared in your 1st post) with the 2.0.2beta3 but I had no clue about the other. Yesterday, I was thinking that I already check if the fragment is attached BUT before posting to the main thread the changes to be applied not when the Runnable is effectively executed, so I decided to move the attached state checking only at the execution time.

I do not reproduce these crashes so I let you try the new 2.0.3beta4 I released to the staging channel of mavenCentral. In order to get it, follow the steps below.

project settings.gradle

dependencyResolutionManagement {
    repositories {
        maven { url "https://s01.oss.sonatype.org/content/groups/staging/" }
    }
}

module build.gradle

implementation 'im.crisp:crisp-sdk:2.0.3beta4'
gekylafas commented 2 weeks ago

That's it, 2.0.3beta4 doesn't crash for me anymore!

Doc1faux commented 2 weeks ago

I've just released the 2.0.3beta4 fixing this crash, it should be available in the next hours :)