Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

flutter pub get fails: version solving failed because of flutter_test from sdk

ErrorBecause every version of flutter_test from sdk depends on

Short answer

The Flutter SDK pins a few packages to exact versions, and flutter_test depends on them. If your pubspec, or a package you use, asks for a version outside that pin, pub cannot solve and blames flutter_test from sdk. Widen the constraint, upgrade the blocking package, or as a short-term step use dependency_overrides.

  • Applies to Flutter 3.3x stable, Dart 3.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the full pub message, not only the last line. It names the package whose version range clashes with the one the SDK pins. Then print the dependency tree to see who asks for that package.

    flutter pub get
    dart pub deps --style=compact
  2. 2Match what you see, then jump to its fix

    1. 1The message names a package you list directly in pubspec.yaml, for example path, collection, characters or metaYour own constraint excludes the version Flutter pinsFix
    2. 2The message names a package that is not in your pubspec.yaml, and a chain such as 'foo depends on bar >=2.0.0'A dependency of a dependency does not allow the pinned versionFix
    3. 3The problem shows only in one tool (CI job, script, or plain dart pub get), while flutter pub get workspub runs without the Flutter SDKFix

What does the error look like?

  • Because every version of flutter_test from sdk depends on
  • flutter_test from sdk is forbidden
  • version solving failed

Cause 1 of 3

Your own constraint excludes the version Flutter pins

1Check

Compare the range you wrote with the range pub reports. Flutter pins some packages (characters, collection and path are named examples), and your constraint must include the pinned version.

grep -n "path:\|collection:\|characters:\|meta:" pubspec.yaml
flutter --version

2Fix

Widen the constraint so it includes the pinned version, for example from a narrow range to a caret range, then run pub again.

dependencies:
  path: ^1.8.0

3Verify

pub resolves and writes pubspec.lock.

flutter pub get

Confirmed by github.com

Did this fix it?

Cause 2 of 3

A dependency of a dependency does not allow the pinned version

1Check

Find which of your direct dependencies pulls in that package, and whether a newer release of it supports the pinned version.

dart pub deps --style=list
dart pub outdated

2Fix

Upgrade the direct dependency to a release that supports the pinned version, or ask its maintainers for one. Until it exists, a dependency override is a short-term way out; remove it as soon as the package is fixed.

dependency_overrides:
  path: 1.9.0

3Verify

pub resolves with the override removed after the upgrade.

flutter pub upgrade

Confirmed by github.com

Did this fix it?

Cause 3 of 3

pub runs without the Flutter SDK

1Check

A dependency with sdk: flutter can only be satisfied when pub runs in the context of the flutter executable. Check which command your pipeline uses.

which flutter dart
grep -rn "pub get" .github ci scripts 2>/dev/null

2Fix

Run flutter pub get, not dart pub get, in Flutter projects, and make sure flutter from the right SDK is on PATH.

flutter pub get

3Verify

The command succeeds and pubspec.lock lists flutter_test with source sdk.

grep -n -A3 "flutter_test" pubspec.lock

Confirmed by dart.dev

Did this fix it?

How do I stop it coming back?

  • Use caret ranges such as ^1.8.0 for direct dependencies, not narrow bounds or single pinned versions.
  • Run flutter pub outdated now and then and upgrade packages in small steps.
  • Keep dependency_overrides out of committed code unless a comment explains when to remove it.
  • Use flutter pub get in scripts and CI for Flutter projects.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.