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
55 stars 17 forks source link

App crashes the first time the user uses the app. #97

Closed kastriotrama closed 2 years ago

kastriotrama commented 2 years ago
screen-shot-2022-03-28-at-1748_9p0c3j

While using the latest crisp sdk(1.0.9), everytime the user tries it for the first time it throws this error, but after it comes back the second time it works, and it won't throw the error even if the user force closes the app.

@Doc1faux @baptistejamin

Doc1faux commented 2 years ago

Hi @kastriotrama and thank you for your feedback.

I tried to reproduce your crash creating a brand new Kotlin app (as this is the exception thrown) as is and I didn't reproduced the crash :/ Then, I tried to import up-to-date socket.io-client, okhttp and/or retrofit libraries as it seems to be related to them but I still not reproduce the crash :/ (I say up-to-date as we use previous versions for Socket.IO to be compatible with Crisp servers and OkHttp and Retrofit to be compatible with Android 4.4). Then I searched specifically for your crash and found this socket.io-client issue. At OkHttp, I found this issue too, but the fix does not seem to have been backported to v3.12.x... Could you try to import v3.14.6 of the OkHttp library in your gradle file to know if it fixes your crash?

implementation 'com.squareup.okhttp3:okhttp:3.14.6'

If so, @baptistejamin we should discuss about dropping Android 4.4 support...

kastriotrama commented 2 years ago

Tried it with v3.14.6 but still crashed, updating to the latest v4.9.2 fixed the issue, thank you for your detailed response @Doc1faux

Even though it opens up the activity it throws this exception.

Screen Shot 2022-03-29 at 13 36 05
Doc1faux commented 2 years ago

Do you deploy your app on a Xiaomi device? Because it seems related to a firmware issue on MIUI while calling Activity.recreate() which Crisp SDK does to apply the correct Chat theming according to the website settings. As I don't own a Xiaomi device to reproduce this crash, I could only provide you a workaround I found which seems to work for some people by disabling auto-dark feature, let me know if it works for you :)

Disable auto-dark feature

Set forceDarkAllowed to false to your app theme and to CrispTheme

<resources xmlns:tools="http://schemas.android.com/tools">
  <style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
  </style>

  <style name="CrispTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
  </style>
</resources>
Doc1faux commented 2 years ago

updating to the latest v4.9.2 fixed the issue

So @baptistejamin do we drop the Android 4.4 support to avoid this crash for kotlin developers?

baptistejamin commented 2 years ago

@Doc1faux go for it

Doc1faux commented 2 years ago

Tried it with v3.14.6 but still crashed, updating to the latest v4.9.2 fixed the issue, thank you for your detailed response @Doc1faux

Even though it opens up the activity it throws this exception.

Screen Shot 2022-03-29 at 13 36 05

I moved this crash in new https://github.com/crisp-im/crisp-sdk-android/issues/99 as I close this issue for the fix in 1.0.10 of the first crash due to OkHttp.