flutter_gen icon indicating copy to clipboard operation
flutter_gen copied to clipboard

Name collision with flutter localization when using build_runner.

Open Nico04 opened this issue 3 years ago • 11 comments

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 ?

Nico04 avatar Nov 03 '20 10:11 Nico04

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 avatar Nov 03 '20 10:11 Nico04

@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?

wasabeef avatar Nov 04 '20 06:11 wasabeef

@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

wasabeef avatar Mar 17 '21 13:03 wasabeef

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

fabiancrx avatar Mar 17 '21 22:03 fabiancrx

I confirm it does work without conflict with flutter_gen_runner: ^2.0.3 and Flutter 1.22.6 Thanks !

Nico04 avatar Mar 18 '21 10:03 Nico04

@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

quangson91 avatar Mar 20 '21 16:03 quangson91

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

quangson91 avatar Mar 25 '21 08:03 quangson91

@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

It seems that still doesn't work with custom config in pubspec.yaml. Any updates on this?

Inakitajes avatar Dec 02 '21 19:12 Inakitajes

@Inakitajes

Which flutter_gen_runner version are you using?

  • latest version
dev_dependencies:
  build_runner:
  flutter_gen_runner: ^4.1.2

wasabeef avatar Dec 10 '21 12:12 wasabeef

Does anyone have new take on this? It is still present in 5.1.0+1

doruchidean avatar Nov 29 '22 14:11 doruchidean

Seems like a flutter issue. Follow this comment maybe resolve the problem: https://github.com/flutter/flutter/issues/69034#issuecomment-719505458

lcdsmao avatar Dec 19 '22 02:12 lcdsmao

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

AlexV525 avatar Mar 05 '24 18:03 AlexV525

And should also be solved by https://github.com/FlutterGen/flutter_gen/issues/53#issuecomment-801071378.

AlexV525 avatar Mar 10 '24 07:03 AlexV525