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

Flutter iOS/Android Release构建内存耗尽错误求助

Flutter Release构建因TypeFlowAnalysis内存耗尽失败,Debug构建正常

之前多次成功构建Release版本,近期突然失败,但Debug构建完全正常,无法确定自上次成功构建后代码或配置发生了哪些变更。

每次尝试iOS Release构建都会生成包含TypeFlowAnalysis的堆栈跟踪,核心错误为内存耗尽,完整日志如下:

[ +608 ms] Persisting file store
[   +1 ms] Done persisting file store
[   +3 ms] "flutter assemble" took 2,571,290ms.
[        ] ensureAnalyticsSent: 0ms
[        ] Running shutdown hooks
[        ] Shutdown hooks complete
[        ] exiting with code 1
[+2568997 ms] Exhausted heap space, trying to allocate 268435488 bytes.

[   +1 ms] Unhandled exception:
           Out of Memory
           #0      _LinkedHashSetMixin._init (dart:collection-patch/compact_hash.dart:824:17)
           #1      _LinkedHashSetMixin._rehash (dart:collection-patch/compact_hash.dart:803:7)
           #2      _LinkedHashSetMixin._add (dart:collection-patch/compact_hash.dart:865:7)
           #3      _DependencyTracker.addDependentInvocation
(package:vm/transformations/type_flow/analysis.dart:59:28)
           #4      TypeFlowAnalysis.applyCall
(package:vm/transformations/type_flow/analysis.dart:1720:20)
           #5      Call.apply (package:vm/transformations/type_flow/summary.dart:268:31)
           #6      Summary.apply (package:vm/transformations/type_flow/summary.dart:724:33)
           #7      _DirectInvocation._processFunction
(package:vm/transformations/type_flow/analysis.dart:307:24)
           #8      _WorkList.processInvocation
(package:vm/transformations/type_flow/analysis.dart:1472:27)
           #9      _DispatchableInvocation.process.<anonymous closure>
(package:vm/transformations/type_flow/analysis.dart:449:44)
           #10     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:617:13)
           #11     _DispatchableInvocation.process
(package:vm/transformations/type_flow/analysis.dart:423:12)
           #12     _WorkList.processInvocation
(package:vm/transformations/type_flow/analysis.dart:1472:27)
           #13     _WorkList.process (package:vm/transformations/type_flow/analysis.dart:1414:7)
           #14     TypeFlowAnalysis.process (package:vm/transformations/type_flow/analysis.dart:1604:14)
           #15     transformComponent (package:vm/transformations/type_flow/transformer.dart:111:20)
           #16     runGlobalTransformations (package:vm/kernel_front_end.dart:492:20)
           #17     compileToKernel (package:vm/kernel_front_end.dart:411:11)
           #18     _rootRunUnary (dart:async/zone.dart:1399:47)
           #19     _FutureListener.handleValue (dart:async/future_impl.dart:147:18)
           #20     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:766:45)
           #21     Future._propagateToListeners (dart:async/future_impl.dart:795:13)
           #22     Future._completeWithValue (dart:async/future_impl.dart:566:5)
           #23     _rootRunUnary (dart:async/zone.dart:1399:47)
           #24     _FutureListener.handleValue (dart:async/future_impl.dart:147:18)
           #25     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:766:45)
           #26     Future._propagateToListeners (dart:async/future_impl.dart:795:13)
           #27     Future._completeWithValue (dart:async/future_impl.dart:566:5)
           #28     _rootRunUnary (dart:async/zone.dart:1399:47)
           #29     _FutureListener.handleValue (dart:async/future_impl.dart:147:18)
           #30     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:766:45)
           #31     Future._propagateToListeners (dart:async/future_impl.dart:795:13)
           #32     _rootRunUnary (dart:async/zone.dart:1399:47)
           ...
           ...
           #39     _rootRunUnary (dart:async/zone.dart:1399:47)
           #40     _FutureListener.handleValue (dart:async/future_impl.dart:147:18)
           #41     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:766:45)
           #42     Future._propagateToListeners (dart:async/future_impl.dart:795:13)
           #43     _rootRunUnary (dart:async/zone.dart:1399:47)
           #44     _FutureListener.handleValue (dart:async/future_impl.dart:147:18)
           #45     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:766:45)
           #46     Future._propagateToListeners (dart:async/future_impl.dart:795:13)
           #47     Future._completeWithValue (dart:async/future_impl.dart:566:5)
           #48     _rootRunUnary (dart:async/zone.dart:1399:47)
           #49     _FutureListener.handleValue (dart:async/future_impl.dart:147:18)
           #50     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:766:45)
           #51     Future._propagateToListeners (dart:async/future_impl.dart:795:13)
           #52     _rootRunUnary (dart:async/zone.dart:1399:47)
           #53     _FutureListener.handleValue (dart:async/future_impl.dart:147:18)
           #54     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:766:45)
           #55     Future._propagateToListeners (dart:async/future_impl.dart:795:13)
           #56     _rootRunUnary (dart:async/zone.dart:1399:47)
           #57     _CustomZone.runUnary (dart:async/zone.dart:1300:19)
           #58     _rootRun (dart:async/zone.dart:1391:13)
           #59     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1225:23)
           #60     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
           #61     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
           #62     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:122:13)
           #63     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:405:11)
           #64     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
           #65     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

已排查的方向

  • Flutter版本:尝试升级至最新稳定版3.7,也降级至上次成功构建时的3.3.6版本,均无效
  • 平台兼容性:iOS构建出现上述堆栈错误;构建Android App Bundle时,64GB内存的M1 Mac系统直接耗尽应用内存
  • 依赖版本:尝试使用上次成功构建时的依赖版本,也升级了所有依赖,均无效
  • 常规清理操作:执行flutter clean、清理Xcode DerivedData、flutter pub cache clean、pod cache clean --all,均未解决问题

参考过相关问题,但其中升级Flutter、清理缓存的方案对Flutter 3+版本的适用性存疑。目前正在通过二分法回溯查找最后正常的提交,但Release构建耗时超1小时,进度缓慢。项目规模较大,包含大量代码生成,但自上次成功构建后项目规模未发生显著变化。

Flutter环境信息

╰─ flutter doctor -v                                                                                                                                                                                ─╯
[✓] Flutter (Channel stable, 3.3.6, on macOS 12.6 21G115 darwin-arm, locale en-US)
    • Flutter version 3.3.6 on channel stable at /Users/alyibrahim/dev/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6928314d50 (3 months ago), 2022-10-25 16:34:41 -0400
    • Engine revision 3ad69d7be3
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/alyibrahim/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = /Users/alyibrahim/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.74.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.58.0

[✓] Connected device (1 available)
    • macOS (desktop) • macos • darwin-arm64 • macOS 12.6 21G115 darwin-arm

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 13:01:05