Skip to content
Latchkey

Flutter "pub get failed" - Connection & Cache Errors in CI

Pub failed to fetch packages from pub.dev. Unlike version-solving failures, this is a download/cache problem - a transient network error or a corrupt local pub cache - and usually clears on retry or a cache repair.

What this error means

flutter pub get fails with a connection-closed, timeout, or "Hash mismatch"/"Failed to extract" error while downloading. Re-running often works, and repairing the pub cache fixes a corrupt download.

pub output
Connection closed while receiving data, package:dio.
pub get failed
Failed to extract package:image to cache: hash mismatch.

Common causes

Transient pub.dev network failure

A dropped connection or timeout while downloading a package. These are flaky and unrelated to your constraints.

Corrupt or partial pub cache

A previous interrupted download left a bad archive in ~/.pub-cache, so extraction fails with a hash mismatch until the cache is repaired.

How to fix it

Retry, then repair the cache

Retry the fetch; if a hash mismatch persists, repair the cache to re-download corrupt entries.

Terminal
flutter pub get || (dart pub cache repair && flutter pub get)

Cache the pub cache between runs

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: ~/.pub-cache
    key: pub-${{ hashFiles('pubspec.lock') }}

Use a mirror for restricted networks

On networks that cannot reach pub.dev directly, point pub at an internal mirror.

Terminal
export PUB_HOSTED_URL=https://pub.your-mirror.example.com
flutter pub get

How to prevent it

  • Cache ~/.pub-cache keyed on pubspec.lock.
  • Wrap pub get with a pub cache repair fallback for corruption.
  • Use an internal mirror for high-volume or restricted pipelines.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →