Flutter 报错: Because every version of flutter_test from sdk depends on xxx, xxx depends on path xxx

Scenario 1: The dependency version used by the project is greater than the version supported by the SDK

For example, the path used in the project depends on version ^1.7.0, but the highest supported by the SDK is 1.6.4, an error will be reported:

[camera_demo] flutter pub getRunning "flutter pub get" in camera_demo... 
Because every version of flutter_test from sdk depends on path 1.6.4 and camera_demo
depends on path ^1.7.0,flutter_test from sdk is forbidden.
So, because camera_demo depends on flutter_test any from sdk, version solving failed.
pub get failed (1; So, because camera_demo depends on flutter_test any from sdk, 
version solving failed.)exit code 1

The focus is:

Because every version of flutter_test from sdk depends on path 1.6.4 and camera_demo depends on path ^1.7.0, flutter_test from sdk is forbidden.

The actual meaning is flutter_test(Flutter test) The path read from the local SDK depends on the highest adapted version 1.6.4, but the path 依赖是 ^1.7.0version used in the actual project, that is, the version of the path in the actual project requires a newer version of the SDK to be used normally (Or understand this, the local SDK cannot meet the latest version of path), so there are two solutions:

1. Upgrade Flutter SDK:

flutter upgrade

2. If you do not want to upgrade the SDK, then an error message which said that according to the version in pubspec.ymlthe specified dependent on the version. For example, to solve the above error:

dependencies:
  flutter:
    sdk: flutter
  # 创建适配任何平台的路径,指定为 1.6.4 版本
  path: 1.6.4

[Recommendation] If it is a new project, it is recommended to upgrade the Flutter SDK to the latest version, otherwise it is recommended to specify the dependent version to avoid the inconsistency between the upgrade SDK and the team's environment, which may cause other problems .

Scenario 2: The dependency version used by the project is lower than the version supported by the SDK

[Note] Generally speaking, it is backward compatible, except that some major version upgrades are not compatible.

Such as local SDK supports collection 依赖the version 1.14.11, but the actual project dependencies lower than this version, the error message is as follows:

Because every version of flutter_test from sdk depends on collection 1.14.11 and flutter_app depends on collection 1.14.6, flutter_test from sdk is forbidden.
So, because flutter_app depends on flutter_test any from sdk, version solving failed.

There are two solutions:

1. If it is a new project, it is recommended to use the latest dependencies, the configuration is as follows:

dependencies:
  flutter:
    sdk: flutter
  # conllection 依赖, 指定版本为 1.14.11 及最新版本,如果想指定到1.14.11版本,请把 ^ 去掉
  # 实际版本可参考错误信息里面提供的版本进行设置
  collection: ^1.14.11

2. If it is a team project, please communicate first, or align yourself Flutter SDKwith other colleagues.

Article blog address: Roc's Blog

Guess you like

Origin blog.csdn.net/peng2hui1314/article/details/106203209