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

Flutter升级至3.0.2后构建App失败 flutter_archive插件报错

问题描述

将Flutter升级到3.0.2稳定版后构建Android端应用时,抛出如下编译错误:

.pub-cache/hosted/pub.dartlang.org/flutter_archive-4.1.1/android/src/main/kotlin/com/kineapps/flutterarchive/FlutterArchivePlugin.kt: (370, 58): Object is not abstract and does not implement abstract member public abstract fun error(p0: String, p1: String?, p2: Any?): Unit defined in io.flutter.plugin.common.MethodChannel.Result

.pub-cache/hosted/pub.dartlang.org/flutter_archive-4.1.1/android/src/main/kotlin/com/kineapps/flutterarchive/FlutterArchivePlugin.kt: (387, 17): 'error' overrides nothing

执行flutter doctor检查开发环境,所有检查项均正常,输出如下:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.2, on macOS 12.1 21C52 darwin-arm, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] Connected device (4 available)
[✓] HTTP Host Availability
故障原因

Flutter 3.0版本调整了io.flutter.plugin.common.MethodChannel.Result接口的error方法签名,第三个入参类型从可空String修改为可空Any。当前使用的flutter_archive 4.1.1版本未适配该变更,Android端Kotlin代码中重写的error方法参数类型和接口定义不匹配,导致重写无效、接口抽象方法未实现,最终编译失败。

解决方案
  • 优先走官方适配:直接把flutter_archive升级到兼容Flutter 3.0的4.2.0及以上版本,在pubspec.yaml里改完版本号跑一次flutter pub get,拉完新依赖就能正常构建,这是最稳妥的方案。
  • 临时救急方案:要是项目里其他依赖卡着暂时升不了flutter_archive,可以直接改本地Pub缓存里的插件代码:顺着报错路径找到FlutterArchivePlugin.kt文件,翻到387行附近重写error方法的位置,把方法第三个参数的类型从String?改成Any?,存完文件重新编译就行。要注意这种改缓存的方式不持久,之后跑flutter pub cache repair、删了依赖重拉的时候修改就会被覆盖,只适合临时跑通构建用。
  • 长效本地适配:如果需要长期用修改后的版本不被重置,可以把flutter_archive 4.1.1的源码拷到项目本地目录,改完Kotlin代码后在pubspec.yaml里用路径方式依赖本地的插件副本,也可以通过dependency_overrides全局覆盖该依赖,避免缓存变动影响构建。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.28 07:24:36