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

Flutter升级后Windows端编译报Custom build exited with code 1错误求解决

Flutter Windows升级后编译失败(Custom build exited with code 1)解决方案

问题原因

升级Flutter及依赖后,多个第三方包未适配新版本Flutter的API变更(如window API废弃、ViewConfiguration移除、手势事件类型调整等),导致编译报错。

解决方案

1. 升级第三方依赖到兼容版本

执行以下步骤更新所有依赖:

  • 运行命令查看可升级的依赖:
    flutter pub outdated
    
  • 修改pubspec.yaml中对应包的版本号为最新稳定版:
    • pluto_grid:替换6.0.4为最新适配版本(建议7.x及以上)
    • printing:替换5.9.3为最新版本(建议6.x及以上)
    • screenshot:替换1.3.0为最新版本(建议2.x及以上)
    • qr_flutter:替换4.1.0为最新版本(建议5.x及以上)
    • flutter_pinput:从旧git分支切换到官方最新发布版,或更新git引用至最新commit
  • 重新安装依赖:
    flutter pub get
    

2. 清理缓存与构建文件

  • 清理Pub缓存:
    flutter pub cache clean
    
  • 删除项目下的Windows构建目录:Windows命令执行 rmdir /s /q build\windows,Linux/macOS执行 rm -r build/windows
  • 重新生成Windows项目配置文件:
    flutter create --platforms windows .
    
  • 重新编译运行:
    flutter run -d windows
    

3. 临时修复个别包(不推荐,仅紧急场景使用)

如果暂时无法升级特定包,可临时修改缓存中的代码:

  • pluto_grid:在报错的pluto_scrollbar.dart文件中,给对应方法添加devicePixelRatio: WidgetsBinding.instance.window.devicePixelRatio参数
  • flutter_pinput:修改手势方法的参数类型为TapDragDownDetails、TapDragUpDetails,并调整调用逻辑

4. 处理CMake警告(非必要)

若要消除CMake的时间戳警告,在项目的windows/CMakeLists.txt中添加:

cmake_policy(SET CMP0135 NEW)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 21:14:54