Search code examples
androidandroid-inflateandroid-10.0inflate-exception

How come I get so many InflateException crashes recently from Samsung devices running Android 10?


Background

For some reason on one of my apps, I get relatively a lot of crashes recently of "android.view.InflateException" . I think it has started over the last version or two.

The problem

According to both the Play Console and Crashlytics, for some reason the crashes occur only on Samsung devices that have Android 10.

It might be a coincidence for now, as Samsung devices are quite popular, but still it is suspicious to me.

On Play Console, it doesn't say much:

https://i.sstatic.net/QZ8D4.png

On Crashlytics, it seems it's related to inflation of views, but it doesn't make sense, because it says it's "Error inflating class TextView" or "Error inflating class androidx.appcompat.widget.Toolbar" :

https://i.sstatic.net/brMgU.png

https://i.sstatic.net/PGRCe.png

What I've tried

Searching the Internet and here, sadly I couldn't find a similar case.

What I can think about is that maybe it's some bug on Google's SDKs that I use, which have some issues with Samsung devices, as they got Android 10 only recently. And since it occurred only over the past 1-2 versions that might be it.

I actually use latest versions of Google's SDKs. However, I don't even use the fancy stuff there. On the Toolbar one, my layout has "CoordinatorLayout", "AppBarLayout", "Toolbar" and "FragmentContainerView" (for the preferences), for example. Here's its layout:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" android:layout_height="match_parent"
    tools:context=".activities.activity_settings.SettingsActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:fitsSystemWindows="true" android:id="@+id/appBarLayout"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay"
            app:title="@string/settings" />

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragmentContainer" android:layout_width="match_parent" android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Here are some of the dependencies I tried to update to, in order to reduce how common the bug is :

  • 'com.google.android.material:material:1.2.0-alpha03'

  • 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'

  • 'androidx.core:core-ktx:1.2.0-rc01'

  • 'androidx.fragment:fragment-ktx:1.2.0-rc04'

  • 'androidx.recyclerview:recyclerview:1.1.0'

  • 'dev.chrisbanes:insetter:0.2.0'

  • 'dev.chrisbanes:insetter-ktx:0.2.0'

The questions

How come it happens ? What could have caused it? I don't see it mentioned anywhere.

Is this perhaps a known bug? How come it's only for Samsung devices with Android 10? I tested it already on my own Pixel 4 with Android 10 (and other devices with other versions of Android) , and it worked fine...


Solution

  • Seems it was all because I used a system color that isn't defined on some devices:

    res/values-v29/colors.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="colorAccent">@*android:color/accent_device_default_light</color>
    </resources>