flutter build stops with 'No file or variants found for asset'
Error detected in pubspec.yaml:Short answer
The build checks every entry under flutter: assets: in pubspec.yaml. It fails when the listed file does not exist and no 2.0x or 3.0x variant exists either. So the entry points at a file that is not there. Copy the exact path from the error and list it. If the message names a package, the missing file is in that dependency.
Fix it fast
1Find out which cause you have
Take the path from the error and check whether that exact file exists, relative to the folder that holds pubspec.yaml.
ls -l assets/images/logo.png grep -n "assets" -A 6 pubspec.yaml2Match what you see, then jump to its fix
What does the error look like?
Error detected in pubspec.yaml:No file or variants found for asset: assets/images/logo.png.This asset was included from package
Cause 1 of 2
The listed path does not match a real file
1Check
The entry is read from the folder containing pubspec.yaml. A wrong folder name, a missing extension, a renamed file or a file that was never committed all leave the entry pointing at nothing. List the folder and compare.
ls -R assets | head -40
git status --short assets2Fix
Correct the entry so it is the exact path of an existing file, or restore the file. To bundle a whole folder list it with a trailing slash; files directly inside are included, subfolders are not.
flutter:
assets:
- assets/images/
- assets/images/icons/3Verify
Refresh packages and build again.
flutter pub get
flutter build apk --debugConfirmed by docs.flutter.dev
Cause 2 of 2
The missing file belongs to a dependency, not your app
1Check
Flutter prints that line when the bad entry is in another package's pubspec. Your own assets are fine; the dependency lists a file its published copy does not contain.
flutter pub deps | grep -i "<name>"
flutter pub outdated2Fix
Upgrade the named package to a version that ships the file. If the newest release still fails, pin an earlier working version in pubspec.yaml, or report it to the package maintainer.
flutter pub upgrade <name>
flutter clean
flutter pub get3Verify
Build again; the 'included from package' line should no longer appear.
flutter build apk --debugConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- List asset folders with a trailing slash and add each subfolder as its own line.
- Run flutter build once in CI so a missing file fails the pipeline, not a release.
- Add the folder to git together with the pubspec.yaml change, so a clean checkout has the file.
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 says Unable to load asset for an image or file that exists
The asset does not exist or has empty data.
Flutter only bundles files that pubspec.yaml lists.
4 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 fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fix