Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name collision with flutter localization when using build_runner. #49

Closed
Nico04 opened this issue Nov 3, 2020 · 13 comments
Closed

Name collision with flutter localization when using build_runner. #49

Nico04 opened this issue Nov 3, 2020 · 13 comments
Assignees
Labels
discussion Want to discuss it
Milestone

Comments

@Nico04
Copy link

Nico04 commented Nov 3, 2020

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
Copy link
Author

Nico04 commented Nov 3, 2020

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

@wasabeef
Copy link
Member

wasabeef commented Nov 4, 2020

@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 wasabeef self-assigned this Nov 4, 2020
@wasabeef wasabeef changed the title Name collision with flutter localization Name collision with flutter localization when using build_runner. Nov 8, 2020
@wasabeef wasabeef added the discussion Want to discuss it label Nov 14, 2020
@lcdsmao lcdsmao pinned this issue Nov 23, 2020
@wasabeef wasabeef added this to the 2.0.0 milestone Feb 20, 2021
@wasabeef
Copy link
Member

wasabeef commented Mar 17, 2021

@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

@fabiancrx
Copy link

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

@Nico04
Copy link
Author

Nico04 commented Mar 18, 2021

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

@quangson91
Copy link

@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 wasabeef reopened this Mar 20, 2021
@quangson91
Copy link

@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 wasabeef unpinned this issue Oct 12, 2021
@Inakitajes
Copy link

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

@wasabeef
Copy link
Member

@Inakitajes

Which flutter_gen_runner version are you using?

  • latest version
dev_dependencies:
  build_runner:
  flutter_gen_runner: ^4.1.2

@doruchidean
Copy link

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

@lcdsmao
Copy link
Member

lcdsmao commented Dec 19, 2022

Seems like a flutter issue.
Follow this comment maybe resolve the problem:
flutter/flutter#69034 (comment)

@AlexV525
Copy link
Member

AlexV525 commented Mar 5, 2024

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: flutter/flutter#102983

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2024
@AlexV525
Copy link
Member

And should also be solved by #53 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Want to discuss it
Projects
None yet
Development

No branches or pull requests

8 participants