flutter_gen
flutter_gen copied to clipboard
Name collision with flutter localization when using build_runner.
This package has the exact same name than the official flutter localization package, resulting in name collision.
After importing flutter_gen package (this package), my localization files are broken.
error: Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'.
Any ideas ?
EDIT I just found that the file ".dart_tool\package_config.json" contains a ref to flutter_gen-1.2.1
{
"name": "flutter_gen",
"rootUri": "../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_gen-1.2.1",
"packageUri": "lib",
"languageVersion": "2.7"
},
And this package is currently at 1.2.1, so I guess the plugin used by Flutter is this one ? So it's the same package after all ? But why it collides then ?
A temp workaround is to comment flutter_gen
in dev_dependencies
after the files are generated, and git track them.
dev_dependencies:
build_runner: ^1.10.4
json_serializable: ^3.5.0
# flutter_gen: ^1.2.1
@Nico04 Thank you so much.
I'm aware of this issue. Can you use Dart CLI or Homebrew instead of build_runner until it's resolved?
@Nico04
I'm sorry for the late reply.
Just now we released v3.0.2
null safety so could you try it?
- Null Safety
- Rename package for build_runner
flutter_gen:
null_safety: true # Optional (default: true)
dev_dependencies:
build_runner:
flutter_gen_runner: ^3.0.2 # Since v2, renamed
I can confirm that it now works and has no conlficts with flutter's new l10n package using build_runner(tested under flutter 2.0.0). Thanks a lot for this awesome package @wasabeef
I confirm it does work without conflict with flutter_gen_runner: ^2.0.3
and Flutter 1.22.6
Thanks !
@wasabeef san, It worked. But sometimes, it doesn't work :|
If we don't have the config futter_gen
in pubspec.yaml like this one:
flutter_gen:
integrations:
flutter_svg: true
=> After run build runner -> it doesn't work. The error message is:
error: Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'.
If I remove those config (flutter_gen) in pubspec.yaml => I can build & run app normaly.
It looks like the key flutter_gen
somehow has a conflict with flutter i10n.
I tested with flutter_gen_runner: ^3.0.2
and flutter 2.0
@wasabeef san,
It seems this issue is related to package:flutter_gen/gen_l10n
(not related to flutter_gen_runner
package).
Detail:
- Add
package:flutter_gen/gen_l10n
to project. - Add
flutter_gen_runner
to project. - Run the build_runner task
flutter packages pub run build_runner build
.
=> After the build_runner run completed (without out error).
=> Build & run app => the error display with message package:flutter_gen/gen_l10n/app_localizations.dart
is not found.
(Note the file .dart_tool/flutter_gen/gen_l10n/app_localizations.dart
is generated).
WORKAROUND
After the build_runner task finished. I have to run flutter packages pub get
again.
Then, now, I can build the project.
@wasabeef san, It worked. But sometimes, it doesn't work :|
If we don't have the config
futter_gen
in pubspec.yaml like this one:flutter_gen: integrations: flutter_svg: true
=> After run build runner -> it doesn't work. The error message is:
error: Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'.
If I remove those config (flutter_gen) in pubspec.yaml => I can build & run app normaly.
It looks like the key
flutter_gen
somehow has a conflict with flutter i10n.I tested with
flutter_gen_runner: ^3.0.2
andflutter 2.0
It seems that still doesn't work with custom config in pubspec.yaml. Any updates on this?
@Inakitajes
Which flutter_gen_runner
version are you using?
- latest version
dev_dependencies:
build_runner:
flutter_gen_runner: ^4.1.2
Does anyone have new take on this? It is still present in 5.1.0+1
Seems like a flutter issue. Follow this comment maybe resolve the problem: https://github.com/flutter/flutter/issues/69034#issuecomment-719505458
There is nothing the package can do until the virtual flutter_gen
package is removed from Flutter-generated codes because we cannot change the library's name. The only workaround at present is synthetic-package: false
for the l10n.
ref: https://github.com/flutter/flutter/issues/102983
And should also be solved by https://github.com/FlutterGen/flutter_gen/issues/53#issuecomment-801071378.