Flutter项目归档失败:Command PhaseScriptExecution报错求助
解决Flutter归档时file包与Dart SDK不兼容的报错
问题根源
你遇到的报错是由于file包6.1.2版本未适配Dart SDK的更新——Dart在File.create和File.createSync方法中新增了exclusive可选参数,但旧版本的file包没有实现该参数,导致重写方法的签名不匹配,最终引发编译错误。
解决方案
更新file包版本
打开项目根目录的pubspec.yaml,找到file依赖项(如果是间接依赖,可通过flutter pub deps查看依赖树定位),将版本号修改为>=6.1.4(该版本开始支持exclusive参数),或者直接指定最新稳定版:dependencies: file: ^6.1.4 # 或更高版本更新依赖并修复缓存
执行以下命令更新依赖并修复pub缓存:flutter pub upgrade flutter pub cache repair清理项目后重新构建
清理项目缓存并重新拉取依赖:flutter clean flutter pub get重新尝试归档
完成上述步骤后,再次执行归档操作即可解决该错误。
错误信息回顾
../../.pub-cache/hosted/pub.dartlang.org/file-6.1.2/lib/src/interface/file.dart:15:16: Error: The method 'File.create' has fewer named arguments than those of overridden method 'File.create'. Future create({bool recursive = false}); ^ org-dartlang-sdk:///third_party/dart/sdk/lib/io/file.dart:232:16: Context: This is the overridden method ('create'). Future create({bool recursive = false, bool exclusive = false}); ^ ../../.pub-cache/hosted/pub.dartlang.org/file-6.1.2/lib/src/interface/file.dart:15:16: Error: The method 'File.create' doesn't have the named parameter 'exclusive' of overridden method 'File.create'. Future create({bool recursive = false}); ^ org-dartlang-sdk:///third_party/dart/sdk/lib/io/file.dart:232:16: Context: This is the overridden method ('create'). Future create({bool recursive = false, bool exclusive = false}); ^ ../../.pub-cache/hosted/pub.dartlang.org/file-6.1.2/lib/src/forwarding/forwarding_file.dart:22:8: Error: The method 'ForwardingFile.createSync' has fewer named arguments than those of overridden method 'File.createSync'. void createSync({bool recursive = false}) => ^ org-dartlang-sdk:///third_party/dart/sdk/lib/io/file.dart:248:8: Context: This is the overridden method ('createSync'). void createSync({bool recursive = false, bool exclusive = false}); ^ ../../.pub-cache/hosted/pub.dartlang.org/file-6.1.2/lib/src/forwarding/forwarding_file.dart:22:8: Error: The method 'ForwardingFile.createSync' doesn't have the named parameter 'exclusive' of overridden method 'File.createSync'. void createSync({bool recursive = false}) => ^ org-dartlang-sdk:///third_party/dart/sdk/lib/io/file.dart:248:8: Context: This is the overridden method ('createSync'). void createSync({bool recursive = false, bool exclusive = false}); ^ Failed to package /Users/williamsonesson/AndroidStudioProjects/WhyAppen. Command PhaseScriptExecution failed with a nonzero exit code
内容的提问来源于stack exchange,提问作者William Sonesson
相关产品推荐
相关产品推荐

