【问题标题】:How come I get so many InflateException crashes recently from Samsung devices running Android 10?为什么我最近从运行 Android 10 的三星设备上收到这么多 InflateException 崩溃?
【发布时间】:2020-04-28 15:28:37
【问题描述】:

背景

由于某种原因在one of my apps 上,我最近遇到了很多“android.view.InflateException”的崩溃。我认为它已经从上一两个版本开始了。

问题

根据 Play 管理中心和 Crashlytics 的说法,由于某种原因,崩溃仅发生在搭载 Android 10 的三星设备上。

现在可能是巧合,因为三星设备很受欢迎,但我仍然对此感到怀疑。

在 Play 管理中心,它并没有说太多:

在 Crashlytics 上,它似乎与视图的膨胀有关,但这没有意义,因为它说它是“Error inflating class TextView”或“Error inflating class androidx.appcompat.widget.Toolbar”:

我尝试过的

搜索互联网和这里,遗憾的是我找不到类似的案例。

我能想到的是,这可能是我使用的谷歌 SDK 上的一些错误,三星设备存在一些问题,因为他们最近才安装了 Android 10。而且由于它只发生在过去的 1-2 个版本中,可能就是这样。

我实际上使用的是最新版本的 Google SDK。但是,我什至不使用那里的花哨的东西。例如,在工具栏一上,我的布局有“CoordinatorLayout”、“AppBarLayout”、“Toolbar”和“FragmentContainerView”(用于首选项)。这是它的布局:

<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>

以下是我尝试更新的一些依赖项,以减少错误的常见程度:

  • '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'

问题

怎么会这样?什么可能导致它?我没有看到任何地方提到它。

这可能是一个已知的错误吗?为什么它只适用于搭载 Android 10 的三星设备?我已经在我自己的带有 Android 10 的 Pixel 4(以及带有其他 Android 版本的其他设备)上对其进行了测试,它运行良好......

【问题讨论】:

    标签: android android-inflate android-10.0 inflate-exception


    【解决方案1】:

    似乎都是因为我使用了一些设备上未定义的系统颜色:

    res/values-v29/colors.xml

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      相关资源
      最近更新 更多