Closed aliyazdi75 closed 3 years ago
I'm curious, what's your reason for using generate: true
together with synthetic-package: false
? Isn't the former specifically for synthetic packages? With non-synthetic packages you'd run flutter gen-l10n
yourself, right? Or did I miss something?
I'm curious, what's your reason for using
generate: true
together withsynthetic-package: false
? Isn't the former specifically for synthetic packages? With non-synthetic packages you'd runflutter gen-l10n
yourself, right? Or did I miss something?
Generate: true just means to generate automatically when doing a build. synthetic-package just specifies what to generate. They are completely separate and nothing tying them together. There is nothing that implies automatic generation only applies to generation of synthetic packages.
The point is that I do not want to have to run the generation manually and I want it generated in a directory where I can easily commit them to source control
Ok, thanks for the explanation. So the problem is that the two are connected in the flutter tool.
If pubspec.yaml
has generate: true
, the flutter tool assumes that the synthetic package is generated and adds flutter_gen
as a dependency to .dart_tool/package_config.json
. However, if l10n.yaml
has synthetic-package: false
, there won't be any synthetic package generated to .dart_tool/flutter_gen
. This is why adding a dummy pubspec.yaml
there "fixes" the problem.
The relevant piece of code where the flutter tool adds the bogus flutter_gen
dependency is here:
https://github.com/flutter/flutter/blob/cd1892f04fda3b6439842a9ab875973bbc52965c/packages/flutter_tools/lib/src/dart/pub.dart#L528
It's called with generateSyntheticPackage = true
from here if pubspec.yaml
has generate: true
:
https://github.com/flutter/flutter/blob/cd1892f04fda3b6439842a9ab875973bbc52965c/packages/flutter_tools/lib/src/commands/packages.dart#L144
https://github.com/flutter/flutter/blob/cd1892f04fda3b6439842a9ab875973bbc52965c/packages/flutter_tools/lib/src/flutter_manifest.dart#L379
For what it's worth, build_runner works with the dart tool because it won't add the flutter_gen
dependency.
dart pub get && dart run build_runner build
flutter pub get && flutter pub run build_runner build
The diff between .dart_tool/package_config.json
generated by the dart tool vs. the flutter tool looks something like this:
--- dart_package_config_2.json 2021-09-16 16:59:20.822186748 +0200
+++ flutter_package_config_2.json 2021-09-16 16:59:34.518193827 +0200
@@ -540,9 +540,14 @@
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.12"
+ },
+ {
+ "name": "flutter_gen",
+ "rootUri": "flutter_gen",
+ "languageVersion": "2.12"
}
],
- "generated": "2021-09-16T14:58:29.544473Z",
+ "generated": "2021-09-16T14:55:37.842621Z",
"generator": "pub",
"generatorVersion": "2.15.0-68.0.dev"
}
whats the correct way to resolve this issue?
The issue is still there
It's hard to track down the current remaining issues in this thread.
Can somebody still facing difficulty here please open a new issue with a short but complete reproduction of the problem so that it is more clear what the current focus is?
Hi, For our project, we only needed to create an empty
pubspec.yaml
name: test description: A new Flutter application. version: 1.0.0 dependencies: dev_dependencies:
here:
.dart_tool/flutter_gen/pubspec.yaml
And the problem went away. Not sure what caused this issue in the first place tho :/
In my case this answer helped.
If there is no pubspec.yaml at .dart_tool/flutter_gen/ i get:
no .../.dart_tool/flutter_gen/pubspec.yaml
found.
generate: true
in pubspec.yaml
is only required if we're using synthetic flutter_gen
package from .dart_tools/flutter_gen
. If you're experiencing this problem because of the flutter gen-l10n
, simply stop using synthetic package by adding synthetic-package: false
to your l10n.yaml
flutter packages pub get
instead of flutter pub get
solved my issue.Before that I ran flutter clean
and deleted pubspec.lock
.
I did not have to make any changes in my project manually.
For some weird reason, running
flutter packages pub get
instead offlutter pub get
solved my issue.Before that I ran
flutter clean
and deletedpubspec.lock
. I did not have to make any changes in my project manually.
flutter packages pub get
works for me. Any links about the difference between flutter pub get
and flutter packages pub get
. I think they should be the same thing.
For some weird reason, running
flutter packages pub get
instead offlutter pub get
solved my issue.Before that I ran
flutter clean
and deletedpubspec.lock
. I did not have to make any changes in my project manually.
flutter packages pub get
works for me. Any links about the difference betweenflutter pub get
andflutter packages pub get
. I think they should be the same thing.
I thought they are the same, based on a stackoverflow answer , but it turns out they are not..
sigh I seem to have just run into this too. On Flutter stable (Flutter 2.10.3
), after I changed my l10n.yaml
to have synthetic-package: false
(and keeping existing generate: true
in pubspec.yml) the next time I went to run build_runner for json_serialisable I got the Unhandled exception: Bad state: Unable to generate package graph,
error mentioned here.
Then doing a:
flutter clean
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
Still gave the same error. Running gen-l10n
also does *not8 fix the issue via https://github.com/flutter/flutter/pull/68206 as mentioned previously because I'm explicitly not using a synthetic package.
What does fix it is instead is running flutter packages pub get
and then running builder runner.
Like @AleksandarSavic95 I am confused as to why one works and the other doesn't as I too thought they were aliases to the same command?
@jakemac53 Could this issue please be reopened?
Possibly flutter packages pub get
creates the package (including pubspec) but flutter pub get
does not?
In any case though I would open a new issue on the flutter repo. All packages must have a pubspec, and they must declare their used dependencies. If they aren't published on pub then the flutter tool should put publish_to: none
to indicate that. But the pubspec must exist for build_runner to work properly.
Best way to solve it is manually.
create in folder ".dart_tool" in your project environment folder called "flutter_gen" then create in the folder "flutter_gen" file called "pubspec.yaml" then write in "pubspec.yaml" this text: " name: sad description: sad "
good luck
in case of more problems: add this to your project pubspec.yaml
dependency_overrides: analyzer: 3.3.0
then flutter clean, then flutter pub get
Deleting generate: true
from pubspec.yaml
works for me. This change will stop automatic generation of l10n.dart
but I can still generate the file by manually executing flutter gen-l10n
command.
I understand generate: true
in pubspec.yaml
is not compatible with synthetic-package: false
in l10n.yaml
. So we need to change either of generate: true
or synthetic-package: false
.
You don't need l10n, remove
generate: true
in
`
flutter:
uses-material-design: true
generate: true
`
I just run flutter clean
and then flutter pub get
may u need this command also
flutter pub run build_runner watch --delete-conflicting-outputs
Happy Codes :)
Simply relying on flutter_gen
as a dev_denpendencies
will solve the issue.
April '23, it happened again to me after a clean. What fixed it was changing the sequence of commands.
When I tried to run build_runner before gen-l10n, I had the error. Swapping them in the sequence fixed it.
Simply relying on
flutter_gen
as adev_denpendencies
will solve the issue.
I THINK THIS IS THE ANSWER.
For me the minimal cleanup needed is .dart_tool/package_config.json
, so I run the following:
rm .dart_tool/package_config.json && dart run build_runner watch --delete-conflicting-outputs
Possibly
flutter packages pub get
creates the package (including pubspec) butflutter pub get
does not?In any case though I would open a new issue on the flutter repo. All packages must have a pubspec, and they must declare their used dependencies. If they aren't published on pub then the flutter tool should put
publish_to: none
to indicate that. But the pubspec must exist for build_runner to work properly.
Replacing flutter packages get
with flutter packages pub get
fixed this issue for me.
I had a similar issue developing on Chrome OS Flex:
chime@penguin:~/dev/x$ dart run build_runner build
Building package executable... (5.4s)
Built build_runner:build_runner.
Unhandled exception:
Bad state: Unable to generate package graph, no `/home/chime/dev/x/.dart_tool/flutter_gen/pubspec.yaml` found.
#0 _pubspecForPath (package:build_runner_core/src/package_graph/package_graph.dart:268:5)
#1 _parsePackageDependencies (package:build_runner_core/src/package_graph/package_graph.dart:242:21)
#2 PackageGraph.forPath (package:build_runner_core/src/package_graph/package_graph.dart:120:33)
<asynchronous suspension>
#3 main (file:///home/chime/.pub-cache/hosted/pub.dev/build_runner-2.4.6/bin/build_runner.dart:27:30)
<asynchronous suspension>
I was able to fix it by changing generate from true to false in my pubspec.yaml like so:
flutter:
uses-material-design: true
generate: false
Is it some issue with intl package?
This is being discussed and tracked at https://github.com/dart-lang/sdk/issues/53696
I got the same exception but my solution was strange:
I generated localization code and files first with:
flutter gen-l10n
and then generating others wıth:
flutter pub run build_runner build
worked seamlessly.
This is being discussed and tracked at dart-lang/sdk#53696
That issue doesn't seem to fix this issue. @jakemac53 can we reopen this issue?
The linked issue has been reopened. Unless we suspect there is a different problem than the conflict between dart pub get
and flutter pub get
we should keep the conversation at https://github.com/dart-lang/sdk/issues/53696
If there is a different issue than the conflict in package resolutions it can be opened as a new issue in this repo.
I'm not sure why this phenomenon occurs, but I have identified the following reproduction conditions and a solution.
If you run pub get even once in a Flutter package that depends on both l10n and build_runner, errors will occur in all subsequent "dart run build_runner build" operations.
Delete the pubspec.lock file right before each "dart run build_runner build". I have automated this process with a script that I am currently using.
I hope my case will be helpful.
If you are not using flutter_gen in your project, then simply removing that dependency from pubspec.yaml and deleting .dart_tool directory can solve it for you.
build_runner: ^1.10.3
flutter packages pub run build_runner build
:flutter doctor -v
: