如何在`flutter upgrade`之后解决依赖问题?

huangapple go评论87阅读模式
英文:

How to solve dependency issues after a `flutter upgrade`?

问题

我在升级后努力解决了所有的依赖问题。

仍然存在一个问题,涉及到以下内容:

$ flutter pub get

解决依赖关系...
因为没有与 >9.0.2 <10.0.0 匹配的 i18n_extension 版本,而 i18n_extension 9.0.2 依赖于 sprintf ^7.0.0,所以 i18n_extension ^9.0.2 需要 sprintf ^7.0.0。
而 optimized_cached_image >=3.0.0 依赖于 sprintf ^6.0.0,因此 i18n_extension ^9.0.2 与 optimized_cached_image >=3.0.0 不兼容。
因此,由于 shokaze 依赖于 i18n_extension ^9.0.2 和 optimized_cached_image ^3.0.0,版本解析失败。
退出代码 1

这是 YAML 文件(我删除了所有不必要的行以方便查看):

environment:
  sdk: '>=2.18.2 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  intl: ^0.18.0 #^0.17.0
  i18n_extension: ^9.0.2 #^5.0.1
  optimized_cached_image: ^3.0.0 #^3.0.1

我并没有明确要求安装 sprintf

我应该如何解决依赖问题?

英文:

I struggled to fix all the dependencies issues I had after the upgrade.

there is still one regarding

$ flutter pub get

Resolving dependencies...
Because no versions of i18n_extension match >9.0.2 <10.0.0 and i18n_extension 9.0.2 depends on sprintf ^7.0.0, i18n_extension ^9.0.2 requires sprintf ^7.0.0.
And because optimized_cached_image >=3.0.0 depends on sprintf ^6.0.0, i18n_extension ^9.0.2 is incompatible with optimized_cached_image >=3.0.0.
So, because shokaze depends on both i18n_extension ^9.0.2 and optimized_cached_image ^3.0.0, version solving failed.
exit code 1

And here is the yaml (I removed all the unnecessary lines for convenience):

environment:
  sdk: '>=2.18.2 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  intl: ^0.18.0 #^0.17.0
  i18n_extension: ^9.0.2 #^5.0.1
  optimized_cached_image: ^3.0.0 #^3.0.1

I don't explicitly ask for sprintf.

How could I solve the dependency issues?

答案1

得分: -1

这是Flutter中的一个常见问题,它发生是因为i18n_extensionoptimized_cached_image这两个包依赖于不同版本的sprintf包。具体来说,i18n_extension依赖于sprintf的版本^7.0.0,而optimized_cached_image依赖于sprintf的版本^6.0.0。这会导致冲突,因为这两个包要求同一依赖的不同版本。

以下是解决此问题的几种方法:

  1. 升级或降级其中一个包 - 检查i18n_extensionoptimized_cached_image的pub.dev列表,看是否有更新的版本可以解决依赖冲突。如果没有较新版本可用,您可以考虑降级其中一个包,前提是它与您的项目兼容。

  2. 覆盖依赖项 - 您可以在pubspec.yaml文件中覆盖sprintf的版本,以使用特定版本。只有在最后一种情况下才应这样做,因为如果覆盖的版本与所有依赖于它的包不兼容,可能会导致意外行为。以下是如何执行此操作的示例:

dependency_overrides:
  sprintf: ^7.0.0
  1. 向包维护者提问 - 如果以上两个选项都不起作用,您可以在其中一个包的GitHub页面上打开问题(根据您认为应更新sprintf依赖项的包),并要求维护者将包更新为与另一个包兼容的sprintf版本。

请记住,在修改pubspec.yaml文件后,运行flutter pub get以更新您的依赖项。

英文:

This is a common problem in Flutter, and it's happening because the packages i18n_extension and optimized_cached_image depend on different versions of the sprintf package. Specifically, i18n_extension depends on version ^7.0.0 of sprintf, while optimized_cached_image depends on version ^6.0.0. This causes a conflict because the two packages require different versions of the same dependency.

Here's a few ways to resolve this issue:

  1. Upgrade or downgrade one of the packages - Check the pub.dev listings for i18n_extension and optimized_cached_image to see if there's a newer version of either package that resolves the dependency conflict. If a newer version isn't available, you might consider downgrading one of the packages if it's compatible with your project.

  2. Override the dependency - You can override the sprintf version in your pubspec.yaml file to use a specific version. This should only be done as a last resort, because it can lead to unexpected behavior if the overridden version isn't compatible with all packages that depend on it. Here's an example of how to do this:

dependency_overrides:
  sprintf: ^7.0.0
  1. Ask the package maintainers - If neither of the above options work, you can open an issue on the GitHub page for one of the packages (whichever one you think should update their sprintf dependency) and ask the maintainers to update the package to use a version of sprintf that's compatible with the other package.

Remember to run flutter pub get after making changes to your pubspec.yaml file to update your dependencies

huangapple
  • 本文由 发表于 2023年6月22日 04:20:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76526858.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定