同时依赖floor_generator^1.2.0和retrofit_generator^4.0.1,版本解析失败

depends on both floor_generator ^1.2.0 and retrofit_generator ^4.0.1, version solving failed

我在我的应用程序中使用 retrofit_generator 和 floor_generator。

retrofit_generator: ^4.0.1
floor_generator: ^1.2.0

当我尝试 运行 flutter packages pub run build_runner build 时收到此错误:

Because no versions of retrofit_generator match >4.0.1 <5.0.0 and retrofit_generator 4.0.1 depends on analyzer ^3.0.0, re
trofit_generator ^4.0.1 requires analyzer ^3.0.0.
And because floor_generator >=1.2.0 depends on analyzer ^2.2.0, retrofit_generator ^4.0.1 is incompatible with floor_gene
rator >=1.2.0.
So, because my_flutter_app depends on both floor_generator ^1.2.0 and retrofit_generator ^4.0.1, version solving failed.
Running "flutter pub get" in my_flutter_app...
pub get failed (1; So, because my_flutter_app depends on both floor_generator ^1.2.0 and retrofit_generator ^4.0.1,
version solving failed.)

此外,尝试在 dev_dependencies 中添加 analyzer: ^3.0.0 然后:

Because floor_generator >=1.2.0 depends on analyzer ^2.2.0 and my_flutter_app depends on analyzer ^3.0.0, floor_generator >=1.2.0 is forbidden.
So, because my_flutter_app depends on floor_generator ^1.2.0, version solving failed.
pub get failed (1; So, because my_flutter_app depends on floor_generator ^1.2.0, version solving failed.)
exit code 1

我们如何才能同时使用两者而不会出错?

检查 retrofit_generator CHANGELOG,您会看到版本 4.0.0 发生了重大变化,使库依赖于版本 3.0.0floor_generator 还没有最近 7 个月的更新,它取决于 analyzer.

的旧版本

可能的解决方案是在重大更改之前降级 retrofit_generator 版本,或者等到 floor_generator 的发布者更新其依赖项。