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

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.drawable.Drawable.isProjected()' on a null object reference #179

Closed dutrasr closed 2 months ago

dutrasr commented 4 months ago

Hi,

I'm seeing the crash bellow in a couple of older android version(8, 8.1 or 9). Newer ones seems fine.

I'm currently using the the 2.0.0beta1 version through the react-native-crisp-chat-sdk package.

FATAL EXCEPTION: main
Process: com.app.name, PID: 10705
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.drawable.Drawable.isProjected()' on a null object reference
    at android.graphics.drawable.LayerDrawable.isProjected(LayerDrawable.java:417)
    at android.view.View.invalidateInternal(View.java:16438)
    at android.view.View.invalidate(View.java:16398)
    at android.view.View.setFrame(View.java:20819)
    at android.view.View.layout(View.java:20669)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at androidx.coordinatorlayout.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1248)
    at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:934)
    at com.google.android.material.bottomsheet.BottomSheetBehavior.onLayoutChild(BottomSheetBehavior.java:576)
    at im.crisp.client.internal.utils.BottomSheetNestedScrollBehavior.onLayoutChild(Unknown Source:0)
    at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:953)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at com.android.internal.policy.DecorView.onLayout(DecorView.java:753)
    at android.view.View.layout(View.java:20672)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
Doc1faux commented 4 months ago

Hi @dutrasr and thank you for your feedback.

I got this crash too on the Crisp app on some Android 7 to 9 devices but for the moment, I did not find the cause of it nor a reproducible case :/

Doc1faux commented 4 months ago

In the end, with a new eye on this crash, I found out that LayerDrawable.setDrawableByLayerId(int id, Drawable drawable) crashes on older Android versions if we set the Drawable to null, which works well on Android 10 and above...

It is used to apply the tiles in the header (or remove them) according to the theme, so from now, instead of setting the drawable from the tile layer to null, I set it to a transparent one.

The fix will be published in the next 2.0.2beta3 release :)

dutrasr commented 4 months ago

Thanks for the prompt reply @Doc1faux.

dutrasr commented 2 months ago

@Doc1faux, until the fix is released, is there any workaround this issue?

Doc1faux commented 2 months ago

Sorry for the late reply, I'll release a new SDK version with only the latest fixes shortly!

Doc1faux commented 2 months ago

I just shipped the new 2.0.2beta3 release which should fix this issue. It can take a couple of hours to be available. I close the issue.