背景
由于某些原因,我最近在我的一个应用程序上遇到了很多"android.view.InflateException“的崩溃。我想它是从上一个版本开始的。
问题所在
根据游戏控制台和Crashlytics的说法,由于某种原因,崩溃只发生在搭载Android 10的三星设备上。
就目前而言,这可能是个巧合,因为三星的设备相当受欢迎,但我仍然对此表示怀疑。
在游戏控制台上,它没有说太多:

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


我试过的
在网上搜索,不幸的是,我找不到类似的情况。
我能想到的是,也许是我使用的Google SDK上的一些bug,三星的设备有一些问题,因为他们最近才买到Android 10。因为它只发生在过去的1-2个版本,所以可能就是它。
实际上,我使用的是谷歌最新版本的SDK。然而,我甚至不使用花哨的东西在那里。例如,在工具栏1上,我的布局有"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>下面是我试图更新的一些依赖项,以减少bug的常见程度:
问题
怎么会发生这种事?是什么导致的?我没看到任何地方都提到过。
这可能是已知的窃听器吗?为什么它只适用于三星的Android 10设备?我已经用Android 10在我自己的Pixel 4上测试了它(还有其他Android版本的设备),它运行得很好.
发布于 2020-01-23 17:23:09
似乎这一切都是因为我使用了一些设备上没有定义的系统颜色:
res/values-v29/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorAccent">@*android:color/accent_device_default_light</color>
</resources>https://stackoverflow.com/questions/59690845
复制相似问题