flutter ビルドエラー「Target of URI doesn't exist...app_localizations...」と対処法

に公開

エラー

Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'. 

Try creating the file referenced by the URI, or try using a URI for a file that does exist.

対処方法

  1. pubspec.yamlを確認 ※generate: trueのプロジェクトは対象
pubspec.yaml
flutter:
  generate: true
  1. l10n.yamlの修正
l10n.yaml
+ synthetic-package: false 
arb-dir: lib/l10n # .arbファイルがあるディレクトリ
- output-localization-file: app_localizations.dart
+ output-dir: lib/generated/i18n
  1. flutter pub get実行
flutter pub get
  1. インポートの修正
- import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+ import 'package:ensembles_app/generated/i18n/app_localizations.dart';
  1. flutter configの実行(任意)
flutter config --explicit-package-dependencies

Discussion