如何从错误中找到标签:在 React Native Android 中尝试使用标签 85273 更新不存在的视图

joc*_*ers 5 debugging crash-reports crashlytics react-native react-native-android

在 React Native 应用程序的生产中,从 firebase 的 crashlytics 获取 Android 上的错误:


    Fatal exception: com.facebook.react.uimanager.IllegalViewOperationException.
    Trying to update non-existent view with tag 85273.

Run Code Online (Sandbox Code Playgroud)

并且没有崩溃的情况,因此无法检测到它。我在模拟器和真正的 Android 设备上检查了很多次。

我们从这次事故中发现了什么?

  • 导致异常的 updateView 方法位于 node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java; 
  

    public void updateView(int tag, String className, ReadableMap props) {
        ViewManager viewManager = mViewManagers.get(className);
        if (viewManager == null) {
          throw new IllegalViewOperationException("Got unknown view type: " + className);
        }
        ReactShadowNode cssNode = mShadowNodeRegistry.getNode(tag);
        if (cssNode == null) {
          throw new IllegalViewOperationException("Trying to update non-existent view with tag " + tag);
        }
    
        if (props != null) {
          ReactStylesDiffMap styles = new ReactStylesDiffMap(props);
          cssNode.updateProperties(styles);
          handleUpdateView(cssNode, className, styles);
        }
      }

Run Code Online (Sandbox Code Playgroud)
  • by condition if cssNode == null, then throw an exception,这意味着一些null来自JS端;
  • ShadowNodeRegistry 是一个简单的容器类,用于跟踪与特定 UIManagerModule 实例关联的 ReactShadowNode;
  • 我们有标签 85273 的编号,这是异常的原因。

如何通过标签号 85273 找到 JS 中的元素?或者也许有人可以推荐我一些文章或分享您的经验,如何在 React Native 应用程序的 Android 中解决这种崩溃。提前致谢。