Maaz Zindani

Loading the index…

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

Flutter cannot find the generated gen_l10n localizations file

ErrorTarget 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.

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

Fix it fast

  1. 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/l10n
  2. 2Match what you see, then jump to its fix

    1. 1Import lines start with package:flutter_gen/gen_l10n/The code still imports package:flutter_genFix
    2. 2No app_localizations.dart is created anywhere after flutter pub getgenerate: true is missing from pubspec.yamlFix
    3. 3The import is relative, but the file is in another folder or has another nameThe generated file is not where the import expects itFix

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 analyze

Confirmed by docs.flutter.dev

Did this fix it?

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.yaml

2Fix

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:any

3Verify

Run pub get and look for the generated files in the arb-dir folder.

flutter pub get
ls lib/l10n

Confirmed by docs.flutter.dev

Did this fix it?

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: false

3Verify

Regenerate and re-run the analyzer.

flutter gen-l10n && flutter analyze

Confirmed by docs.flutter.dev

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

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