flutter pub get: flutter_lints any (authorization failed), version solving failed
Because my_app depends on flutter_lints any which doesn't exist (authorization failed), version solving failed.Short answer
Pub asked a package server for flutter_lints and the server refused it, so pub treats the package as missing. The server is not pub.dev when PUB_HOSTED_URL points to a mirror, or when a hosted entry names a private repository. Unset or correct that address, or add a valid token for the repository with dart pub token add.
Fix it fast
1Find out which cause you have
Print the pub server address your shell gives pub, and look for hosted entries in pubspec.yaml.
echo "PUB_HOSTED_URL=$PUB_HOSTED_URL" grep -n -B1 -A3 "hosted" pubspec.yaml2Match what you see, then jump to its fix
- 1
echo shows a value that is not https://pub.dev, often from a shell profile or a CI setting.PUB_HOSTED_URL points at a mirror or private serverFix - 2
The hosted URL in pubspec.yaml or in PUB_HOSTED_URL is a private repository that asks for authentication.The repository needs a token and pub has none storedFix - 3
The pubspec entry for flutter_lints has a hosted: block with a custom url.flutter_lints is declared with a hosted URL that is not pub.devFix
- 1
What does the error look like?
Because my_app depends on flutter_lints any which doesn't exist (authorization failed), version solving failed.version solving failed
Cause 1 of 3
PUB_HOSTED_URL points at a mirror or private server
1Check
PUB_HOSTED_URL changes where pub downloads dependencies. A mirror that needs a login or lacks the package answers with a refusal, and pub reports it as missing.
env | grep PUB_
grep -n PUB_HOSTED_URL ~/.zshrc ~/.bashrc ~/.profile 2>/dev/null2Fix
Unset the variable for this shell, or point it at a mirror that works. Remove the line from the profile if you no longer need the mirror.
unset PUB_HOSTED_URL
flutter pub get3Verify
pub get resolves flutter_lints from pub.dev.
flutter pub getConfirmed by dart.dev
Cause 2 of 3
The repository needs a token and pub has none stored
1Check
Pub sends requests without authentication when it has no token for a repository URL. A repository that wants a token then refuses the request.
grep -n -B2 -A3 "hosted" pubspec.yaml2Fix
Add the token for that exact repository URL. Pub prompts for the secret. In CI use the env-var form so the secret is not saved.
dart pub token add https://dart-packages.example.com
# CI: read the secret from an environment variable
dart pub token add https://dart-packages.example.com --env-var MY_SECRET_TOKEN3Verify
Run pub get again.
dart pub getConfirmed by dart.dev
Cause 3 of 3
flutter_lints is declared with a hosted URL that is not pub.dev
1Check
A hosted dependency names its repository in pubspec.yaml. If the URL there is wrong or private, pub asks that server and not pub.dev.
grep -n -A4 "flutter_lints" pubspec.yaml2Fix
Use the plain version form for packages on pub.dev.
dev_dependencies:
flutter_lints: any # or the version shown on pub.dev3Verify
Resolve the dependencies again.
flutter pub getConfirmed by dart.dev
How do I stop it coming back?
- Keep mirror settings in one documented place, and say so in the project README.
- Use the --env-var form for tokens on CI instead of a stored secret.
- Check the flutter_lints version on pub.dev before copying a constraint from an old project.
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
flutter pub get fails and no packages are downloaded
Got socket error trying to find package
Run pub get in a terminal and read the first error.
4 causes, each with a fixMobile apps
pub get fails with version solving failed after an SDK or package change
Because app requires SDK version >=2.15.1 <3.0.0, version solving failed.
Version solving fails when no package version fits both your SDK and every other constraint.
5 causes, each with a fixMobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fix