Dart项目依赖冲突求助:test_coverage不支持空安全致版本解析失败
解决Dart 3.2.6版本解析失败问题
问题根源
你遇到的版本解析失败,核心原因是test_coverage >=0.1.1不支持空安全,且其SDK约束为>=2.0.0-dev.66.0 <3.0.0,和你当前使用的Dart 3.2.6(完全支持空安全的高版本SDK)存在兼容性冲突。
可行解决方案
- 替换为官方支持空安全的包:放弃
test_coverage,改用官方维护的coverage包。修改pubspec.yaml中的依赖项:
执行dependencies: # 移除test_coverage coverage: ^1.6.3 # 可使用最新稳定版本dart pub get更新依赖即可。 - 降级Dart SDK版本:如果必须依赖
test_coverage,可按照提示将SDK降级到2.19.6。在pubspec.yaml中指定SDK约束:
切换到对应版本的Dart SDK后重新执行environment: sdk: '>=2.19.6 <3.0.0'dart pub get。 - 自行迁移包到空安全:若
test_coverage已停止维护,可fork其代码仓库,将SDK约束升级为>=2.12.0,完成空安全迁移,然后在pubspec.yaml中引用你的fork版本:dependencies: test_coverage: git: url: https://github.com/你的用户名/test_coverage.git ref: 你的分支名
原始错误信息
Because mrz_parser depends on test_coverage >=0.1.1 which doesn't support null safety, version solving failed.
The lower bound of "sdk: '>=2.0.0-dev.66.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.
For details, see https://dart.dev/null-safetyYou can try the following suggestion to make the pubspec resolve:
- Try using the Dart SDK version: 2.19.6. See https://dart.dev/get-dart.
Process finished with exit code 1
内容的提问来源于stack exchange,提问作者umair khan
相关产品推荐
相关产品推荐

