You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

更新Flutter后应用无法运行,如何排查依赖兼容性问题?

升级Flutter后Target kernel_snapshot失败问题的解决过程

问题背景

升级Flutter至最新版本后,应用无法正常运行,编译时抛出Target kernel_snapshot failed: Exception错误。检查pubspec.yaml中的直接依赖未发现过时项,但报错的flutter_math_fork和flutter_layout_grid属于Flutter相关依赖包。

完整错误日志

../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_math_fork-0.5.0/lib/src/widgets/selection/gesture_detector_builder.dart:186:20: Error: The argument type 'void Function(TapDownDetails)' can't be assigned to the parameter type 'void Function(TapDragDownDetails)?'.
 - 'TapDownDetails' is from 'package:flutter/src/gestures/tap.dart' ('../../flutter/packages/flutter/lib/src/gestures/tap.dart').
 - 'TapDragDownDetails' is from 'package:flutter/src/widgets/tap_and_drag_gestures.dart' ('../../flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart').
        onTapDown: onTapDown,
                   ^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_math_fork-0.5.0/lib/src/widgets/selection/gesture_detector_builder.dart:190:24: Error: The argument type 'void Function(TapUpDetails)' can't be assigned to the parameter type 'void Function(TapDragUpDetails)?'.
 - 'TapUpDetails' is from 'package:flutter/src/gestures/tap.dart' ('../../flutter/packages/flutter/lib/src/gestures/tap.dart').
 - 'TapDragUpDetails' is from 'package:flutter/src/widgets/tap_and_drag_gestures.dart' ('../../flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart').
        onSingleTapUp: onSingleTapUp,
                       ^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_math_fork-0.5.0/lib/src/widgets/selection/gesture_detector_builder.dart:195:26: Error: The argument type 'void Function(TapDownDetails)' can't be assigned to the parameter type 'void Function(TapDragDownDetails)?'.
 - 'TapDownDetails' is from 'package:flutter/src/gestures/tap.dart' ('../../flutter/packages/flutter/lib/src/gestures/tap.dart').
 - 'TapDragDownDetails' is from 'package:flutter/src/widgets/tap_and_drag_gestures.dart' ('../../flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart').
        onDoubleTapDown: onDoubleTapDown,
                         ^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_math_fork-0.5.0/lib/src/widgets/selection/gesture_detector_builder.dart:196:31: Error: The argument type 'void Function(DragStartDetails)' can't be assigned to the parameter type 'void Function(TapDragStartDetails)?'.
 - 'DragStartDetails' is from 'package:flutter/src/gestures/drag_details.dart' ('../../flutter/packages/flutter/lib/src/gestures/drag_details.dart').
 - 'TapDragStartDetails' is from 'package:flutter/src/widgets/tap_and_drag_gestures.dart' ('../../flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart').
        onDragSelectionStart: onDragSelectionStart,
                              ^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_math_fork-0.5.0/lib/src/widgets/selection/gesture_detector_builder.dart:197:32: Error: The argument type 'void Function(DragStartDetails, DragUpdateDetails)' can't be assigned to the parameter type 'void Function(TapDragUpdateDetails)?'.
 - 'DragStartDetails' is from 'package:flutter/src/gestures/drag_details.dart' ('../../flutter/packages/flutter/lib/src/gestures/drag_details.dart').
 - 'DragUpdateDetails' is from 'package:flutter/src/gestures/drag_details.dart' ('../../flutter/packages/flutter/lib/src/gestures/drag_details.dart').
 - 'TapDragUpdateDetails' is from 'package:flutter/src/widgets/tap_and_drag_gestures.dart' ('../../flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart').
        onDragSelectionUpdate: onDragSelectionUpdate,
                               ^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_math_fork-0.5.0/lib/src/widgets/selection/gesture_detector_builder.dart:198:29: Error: The argument type 'void Function(DragEndDetails)' can't be assigned to the parameter type 'void Function(TapDragEndDetails)?'.
 - 'DragEndDetails' is from 'package:flutter/src/gestures/drag_details.dart' ('../../flutter/packages/flutter/lib/src/gestures/drag_details.dart').
 - 'TapDragEndDetails' is from 'package:flutter/src/widgets/tap_and_drag_gestures.dart' ('../../flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart').
        onDragSelectionEnd: onDragSelectionEnd,
                            ^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_layout_grid-1.0.6/lib/src/widgets/placement.dart:82:55: Error: A value of type 'RenderObject?' can't be assigned to a variable of type 'AbstractNode?'.
 - 'RenderObject' is from 'package:flutter/src/rendering/object.dart' ('../../flutter/packages/flutter/lib/src/rendering/object.dart').
 - 'AbstractNode' is from 'package:flutter/src/foundation/node.dart' ('../../flutter/packages/flutter/lib/src/foundation/node.dart').
      final AbstractNode? targetParent = renderObject.parent;
                                                      ^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_layout_grid-1.0.6/lib/src/widgets/placement.dart:83:58: Error: The method 'markNeedsPlacement' isn't defined for the class 'AbstractNode?'.
 - 'AbstractNode' is from 'package:flutter/src/foundation/node.dart' ('../../flutter/packages/flutter/lib/src/foundation/node.dart').
Try correcting the name to the name of an existing method, or defining a method named 'markNeedsPlacement'.
      if (targetParent is RenderLayoutGrid) targetParent.markNeedsPlacement();
                                                         ^^^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_layout_grid-1.0.6/lib/src/widgets/placement.dart:84:54: Error: The method 'markNeedsLayout' isn't defined for the class 'AbstractNode?'.
 - 'AbstractNode' is from 'package:flutter/src/foundation/node.dart' ('../../flutter/packages/flutter/lib/src/foundation/node.dart').
Try correcting the name to the name of an existing method, or defining a method named 'markNeedsLayout'.
      if (targetParent is RenderObject) targetParent.markNeedsLayout();
                                                     ^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_layout_grid-1.0.6/lib/src/widgets/placement.dart:132:55: Error: A value of type 'RenderObject?' can't be assigned to a variable of type 'AbstractNode?'.
 - 'RenderObject' is from 'package:flutter/src/rendering/object.dart' ('../../flutter/packages/flutter/lib/src/rendering/object.dart').
 - 'AbstractNode' is from 'package:flutter/src/foundation/node.dart' ('../../flutter/packages/flutter/lib/src/foundation/node.dart').
      final AbstractNode? targetParent = renderObject.parent;
                                                      ^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_layout_grid-1.0.6/lib/src/widgets/placement.dart:133:58: Error: The method 'markNeedsPlacement' isn't defined for the class 'AbstractNode?'.
 - 'AbstractNode' is from 'package:flutter/src/foundation/node.dart' ('../../flutter/packages/flutter/lib/src/foundation/node.dart').
Try correcting the name to the name of an existing method, or defining a method named 'markNeedsPlacement'.
      if (targetParent is RenderLayoutGrid) targetParent.markNeedsPlacement();
                                                         ^^^^^^^^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_layout_grid-1.0.6/lib/src/widgets/placement.dart:134:54: Error: The method 'markNeedsLayout' isn't defined for the class 'AbstractNode?'.
 - 'AbstractNode' is from 'package:flutter/src/foundation/node.dart' ('../../flutter/packages/flutter/lib/src/foundation/node.dart').
Try correcting the name to the name of an existing method, or defining a method named 'markNeedsLayout'.
      if (targetParent is RenderObject) targetParent.markNeedsLayout();
                                                     ^^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\jjj\Documents\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s
Exception: Gradle task assembleDebug failed with exit code 1

已尝试的无效操作

  • 创建全新Flutter项目并复制原项目lib目录,问题未解决
  • 修复并删除pub缓存,无效
  • 全新的Flutter计数器示例应用可正常构建运行

最终解决方法

报错的flutter_math_fork和flutter_layout_grid并非手动安装的直接依赖,而是flutter_html的间接依赖。移除flutter_html包,更换为其他处理HTML文本的包后,应用可正常运行。

内容的提问来源于stack exchange,提问作者Gse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 15:12:11