Flutter cannot find the generated gen_l10n localizations file
Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'Short answer
Flutter 3.32 stopped creating the package:flutter_gen package. Generated localization files now sit in your own source folder, and generate: true must be in pubspec.yaml. Set synthetic-package: false in l10n.yaml, run flutter gen-l10n, and import the file by its relative path.
Fix it fast
1Find out which cause you have
Check the three things that decide where the file lives: the generate flag, the l10n.yaml settings and whether the generated file exists.
grep -n "generate" pubspec.yaml cat l10n.yaml flutter gen-l10n ls lib/l10n2Match what you see, then jump to its fix
- 1
Import lines start with package:flutter_gen/gen_l10n/The code still imports package:flutter_genFix - 2
No app_localizations.dart is created anywhere after flutter pub getgenerate: true is missing from pubspec.yamlFix - 3
The import is relative, but the file is in another folder or has another nameThe generated file is not where the import expects itFix
- 1
What does the error look like?
Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/gallery_localizations.dart'
Cause 1 of 3
The code still imports package:flutter_gen
1Check
Since Flutter 3.32 the tool no longer generates a synthetic package:flutter_gen package. The files are written into your source directory instead.
grep -rn "flutter_gen" lib/ test/2Fix
Set synthetic-package to false in l10n.yaml, then replace the old import with a relative import of the generated file (the path depends on arb-dir or output-dir).
# l10n.yaml
synthetic-package: false
arb-dir: lib/l10n
// lib/main.dart: before
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
// after
import 'l10n/app_localizations.dart';3Verify
Run the analyzer. The import error goes away.
flutter gen-l10n && flutter analyzeConfirmed by docs.flutter.dev
Cause 2 of 3
generate: true is missing from pubspec.yaml
1Check
Generation runs only when the flutter section of pubspec.yaml enables it. The breaking-change page says generate: true is now required to use generated localization source.
sed -n '/^flutter:/,/^[a-z]/p' pubspec.yaml2Fix
Add the flag, and make sure flutter_localizations and intl are dependencies.
flutter:
generate: true
# then in a terminal
flutter pub add flutter_localizations:"{sdk: flutter}" intl:any3Verify
Run pub get and look for the generated files in the arb-dir folder.
flutter pub get
ls lib/l10nConfirmed by docs.flutter.dev
Cause 3 of 3
The generated file is not where the import expects it
1Check
Output goes to arb-dir by default, or to output-dir if you set it. The file name comes from output-localization-file, which defaults to app_localizations.dart, and the template file defaults to app_en.arb.
cat l10n.yaml
find lib -name "app_localizations*.dart"2Fix
Make arb-dir, output-dir and output-localization-file in l10n.yaml match the folder and file name in your import. Note that output-dir only works together with synthetic-package: false.
# l10n.yaml
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
synthetic-package: false3Verify
Regenerate and re-run the analyzer.
flutter gen-l10n && flutter analyzeConfirmed by docs.flutter.dev
How do I stop it coming back?
- Commit l10n.yaml and keep generate: true in pubspec.yaml.
- Import the generated file by relative path, never through package:flutter_gen.
- Run flutter gen-l10n in CI before flutter analyze if generated files are not committed.
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
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 fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix