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

google_fonts 2.1.0与audioplayers 0.10.0无法运行,版本冲突如何解决?

Flutter Pub 版本冲突解决方法

报错信息:
由于google_fonts >=2.0.0依赖path_provider ^2.0.0,audioplayers >=0.8.2 <0.12.0依赖path_provider ^0.5.0,因此google_fonts >=2.0.0与audioplayers >=0.8.2 <0.12.0版本不兼容。
因xylophone项目同时依赖audioplayers ^0.10.0和google_fonts ^2.1.0,版本解算失败,pub get执行失败(退出码1)

以下是三种可行的解决方法,按优先级排序:

  • 方案1:升级audioplayers版本(优先推荐)
    你当前使用的audioplayers 0.10.0属于较老的版本,0.12.0及以上版本的audioplayers已经适配了path_provider 2.0+。你只需要将pubspec.yaml文件中的audioplayers: ^0.10.0修改为audioplayers: ^4.0.1(可替换为官方最新稳定版),之后执行flutter pub get即可解决冲突。该方案无需调整google_fonts版本,也不会影响现有功能的正常使用。
  • 方案2:降级google_fonts版本
    如果你暂时不需要google_fonts 2.x的新特性,也可以选择降级google_fonts到1.x版本适配旧版audioplayers。将pubspec.yaml文件中的google_fonts: ^2.1.0修改为google_fonts: ^1.1.2,之后执行flutter pub get即可。
  • 方案3:使用依赖覆盖强制指定版本(临时调试用)
    如果你需要同时保留当前两个包的版本,可以在pubspec.yaml中添加依赖覆盖配置,强制指定path_provider的版本,跳过版本校验:
    dependency_overrides:
      path_provider: ^2.0.15
    
    该方案属于临时兼容手段,强制覆盖的依赖版本可能会导致旧版audioplayers出现未预期的异常,不建议长期在正式项目中使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 03:27:01