致命异常:java.lang.StackOverflowError 堆栈大小 8MB android.view.View.hasIdentityMatrix

Fatal Exception: java.lang.StackOverflowError stack size 8MB android.view.View.hasIdentityMatrix

这是我的应用程序中发生的一个非常罕见的错误。用户打开 SettingsActivity 并注意到应用已冻结,然后崩溃(5 - 10 秒后?)。
我不知道如何继续,我试过调试但无法重现问题。我见过其他类似的问题,但他们的堆栈跟踪具有导致无限循环的应用程序方法。在这里,没有负责的应用程序代码(至少,堆栈跟踪没有显示任何内容)

堆栈跟踪仅显示了一堆 Android 核心库方法(ViewViewGroupRecyclerView),并且与可访问性有关。

这让我很困惑,因为:

考虑到堆栈跟踪没有显示我的代码库的任何自定义 classes/methods 部分,我应该如何继续?例如,这是 androidx.recyclerview 中的已知错误吗?

我确定该应用程序会在 SettingsActivity 中崩溃,因为 Firebase 会为您跟踪 Crashlytics 中的活动。 (流量为 MainActivity -> [AnyActivity] -> SettingsActivity -> <freeze> -> <crash>)。

我们整个团队无法重现此问题(使用完全相同的 Play 商店版本),但似乎有大约 100 名用户遇到了此崩溃。我们团队正在使用所有显示这些致命异常的设备进行调试,但无济于事。

堆栈跟踪

Fatal Exception: java.lang.WhosebugError: stack size 8MB
       at android.view.View.hasIdentityMatrix (View.java:14669)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6138)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6189)
       at android.view.ViewGroup.getChildVisibleRect (ViewGroup.java:6121)
       at android.view.View.getGlobalVisibleRect (View.java:16064)
       at android.view.View.isVisibleToUser (View.java:9065)
       at android.view.View.isVisibleToUser (View.java:9023)
       at android.view.View.onInitializeAccessibilityNodeInfoInternal (View.java:8814)
       at android.view.ViewGroup.onInitializeAccessibilityNodeInfoInternal (ViewGroup.java:3642)
       at android.view.View$AccessibilityDelegate.onInitializeAccessibilityNodeInfo (View.java:27387)
       at androidx.core.view.AccessibilityDelegateCompat.onInitializeAccessibilityNodeInfo (AccessibilityDelegateCompat.java:275)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:124)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate$ItemDelegate.onInitializeAccessibilityNodeInfo (RecyclerViewAccessibilityDelegate.java:131)
       at androidx.core.view.AccessibilityDelegateCompat$AccessibilityDelegateAdapter.onInitializeAccessibilityNodeInfo (AccessibilityDelegateCompat.java:86)
       at android.view.View.onInitializeAccessibilityNodeInfo (View.java:7776)
       at android.view.View.createAccessibilityNodeInfoInternal (View.java:7737)
       at android.view.View$AccessibilityDelegate.createAccessibilityNodeInfo (View.java:27485)
       at android.view.View.createAccessibilityNodeInfo (View.java:7720)
       at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode (AccessibilityInteractionController.java:1147)
       at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos (AccessibilityInteractionController.java:972)
       at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread (AccessibilityInteractionController.java:336)
       at android.view.AccessibilityInteractionController.access0 (AccessibilityInteractionController.java:67)
       at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage (AccessibilityInteractionController.java:1324)
       at android.os.Handler.dispatchMessage (Handler.java:106)
       at android.os.Looper.loop (Looper.java:193)
       at android.app.ActivityThread.main (ActivityThread.java:6898)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:537)
       at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)

设置活动

public class SettingsActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        settingsFragment = new SettingsFragment();

        getSupportFragmentManager().beginTransaction()
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                .replace(R.id.settings_container, settingsFragment, "Settings")
                .commit();

        ... // also contains code to init an IAP helper,
            // but that doesn't use RecyclerView either (obviously)

}

设置片段

public class SettingsFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener {
    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        ...
        addPreferencesFromResource(R.xml.preferences);
        ...
}

更新 3

已修复。现在你可以使用最新版本的recyclerview:

implementation 'androidx.recyclerview:recyclerview:1.1.0'

更新 2

This known bug 已在早期版本的 recyclerview (beta03, beta04) 中修复,但现在又回到了 beta05.

所以使用:

implementation 'androidx.recyclerview:recyclerview:1.1.0-beta04'

直到此问题在下一版本中得到解决。


更新 1

此错误已在 recyclerview:1.1.0-beta03 中修复,因此请使用:

implementation 'androidx.recyclerview:recyclerview:1.1.0-beta03'

旧答案

如果您正在使用 recyclerview:1.1.0-beta02,请将其降级为 beta01。 beta02 有这个错误,你和我都遇到过。所以使用这个版本的 Recyclerview:

 implementation 'androidx.recyclerview:recyclerview:1.1.0-beta01'
 //implementation 'androidx.preference:preference:1.1.0-rc01'

直到此问题在下一版本中得到解决。


这是由 Recyclerview class 中的私有代码引起的。我不确定崩溃是否在 Recyclerview 的这个方法中:

// called by accessibility delegate
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfoCompat info) {
    onInitializeAccessibilityNodeInfo(mRecyclerView.mRecycler, mRecyclerView.mState, info);
}

PreferenceFragmentCompat 正在通过嵌套调用使用此方法。所以我们将通过扩展 PreferenceFragmentCompat 来面对这个异常(对我来说,我还应该 setOnPreferenceChangeListener 偏好对象并调用此回调以发生 Whosebug)。但正如我提到的,这个问题在 recyclerview:1.1.0-beta01.

中不存在