Closed aliyazdi75 closed 3 years ago
It sounds like build_runner was ran from inside the .dart_tool/flutter_gen
directory instead of from the root directory for the package?
Hi @jakemac53
No, I was running from the root directory: ~/Documents/AndroidStudioProjects/koja_beram_app$ flutter packages pub run build_runner build
Inside my .dart_tool/flutter_gen
there is no pubspec.yaml
.
The build package doesn't read from the .dart_tool/flutter_gen
directory which is why I am confused.
cc @jonahwilliams do you know what the deal is with that?
@jakemac53
I am wondering it works for my previous flutter applications, but in my new application doesn't.
I don't know is it relevant or not but I have l10n.yaml
file and it builds a gen_l10n
inside .dart_tool/flutter_gen
.
I don't know is it relevant or not but I have l10n.yaml file and it builds a gen_l10n inside .dart_tool/flutter_gen.
I tried removing l10n.yaml
and then flutter clean
and flutter packages pub get
and it fixed!
Ok, the build
package does require a pubspec.yaml
to exist for all packages. It sounds like maybe that was generating some sort of special package that has no pubspec.yaml?
Do you mean that gen_l10n
should have pubspec.yaml
? So, I should submit an issue in flutter repository?
Hi @shihaohong, can you help me with this localization issue?
@aliyazdi75 .dart_tool/flutter_gen
should not contain a pubspec.yaml
because it should only contain synthetic packages, such as the gen_l10n
synthetic package in your case. It seems like the correct behavior is that build_runner
should ignore .dart_tool/flutter_gen
(I'm not sure if it should also ignore the rest of .dart_tool
) when generating a package graph.
It wouldn't necessarily be wrong to also generate a pubspec.yaml there, especially if it smooths things over with build runner.
We do require a pubspec. It doesn't have to be a particularly meaningful one, but we do rely on knowning the direct dependencies of each package for a lot of hueristics (for ordering build steps and things). This is a fundamental constraint of the system.
Plenty of other tools expect a pubspec to exist for all packages as well, I would just put a minimal one in there.
@shihaohong is this something you could take a look at?
I can take a stab at it!
Any news about the issue? Now that Flutter 1.22 is out, I was following the guide to set up the new internationalization system.
The guide says to add a new l10n.yaml
file and
flutter:
# Adds code generation (synthetic package) support
generate: true
Inside .dart_tool
is generated flutter_gen\gen_l10n
with the localization files.
Currently, I am unable to run the generator at all. @shihaohong Is there any workaround or should I wait to include the new internationalization?
I removed the l10n.yaml
and the problem was still there.
The problem error disappears when I remove generate: true
from pubspec.yaml
. May this information help?
Same here. (Tried 1.10.1, 1.10.2, 1.10.3)
generate: false
will fix the build_runner, but will break the new l10n integration.
Bad state: Unable to generate package graph, no `/Users/mark/Projects/flutter/bunch-flutter/.dart_tool/flutter_gen/pubspec.yaml` found.
#0 _pubspecForPath (package:build_runner_core/src/package_graph/package_graph.dart:235:5)
#1 _parsePackageDependencies (package:build_runner_core/src/package_graph/package_graph.dart:208:21)
#2 PackageGraph.forPath (package:build_runner_core/src/package_graph/package_graph.dart:97:33)
<asynchronous suspension>
#3 PackageGraph.forThisPackage (package:build_runner_core/src/package_graph/package_graph.dart:110:20)
#4 main (file:///Users/mark/.pub-cache/hosted/pub.dartlang.org/build_runner-1.10.3/bin/build_runner.dart:27:49)
#5 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#6 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
If I add a empty pubspec.yaml in the flutter_gen directory. The build is working again
name: test
description: A new Flutter application.
version: 1.0.0
dependencies:
dev_dependencies:
Thanks @mark-apn worked for me too
Same issue for me. Any news?
Slightly offtopic, but have you guys noticed how slow Buildrunner is nowadays?
@KlausJokinen if you have noticed a regression please do file an issue - it could be due to app size as well but there are things you can do to alleviate that. Most builders by default will end up running on a lot more files than they need to (all dart files...) and especially if they rely on analysis that can be quite expensive for large projects.
@KlausJokinen if you have noticed a regression please do file an issue - it could be due to app size as well but there are things you can do to alleviate that. Most builders by default will end up running on a lot more files than they need to (all dart files...) and especially if they rely on analysis that can be quite expensive for large projects.
Thanks @jakemac53. Is it possible to trigger build_runner on a specific file/files?
Yes - there is a command line flag --build-filter
which accepts globs of output files to build. But note that it will also generate any files required by those matching files which will mean all transitively imported generated code. That also means any builders you have will still run on all the transitive imports of the primary inputs for the files you are asking it to generate. The result is that in terms of Dart code generation it likely won't help much, but you can try it.
A better option is to configure the generate_for
globs for your builders, which will make them only ever run on certain files. Note that for source_gen based builders for instance by default they will run on (and analyze) all Dart files in your package, even the ones that don't need codegen (it does this to determine if it needs to run, looking for annotations). You can configure these to only run on the files you know they need to run on in your build.yaml
roughly like this:
targets:
$default:
builders:
json_serializable: # This is the builder "key", which is usually the package name for the builder
generate_for:
- lib/models/*.dart
@KlausJokinen I am going to hide our somewhat off topic conversation just to clean up the thread here - if you have further questions please open an issue and we will be happy to discuss there :)
just add pubspec.yaml
to .dart_tool/flutter_gen
can fix the issue:
content of pubspec.yaml
is this:
dependencies:
just add
pubspec.yaml
to.dart_tool/flutter_gen
can fix the issue: content ofpubspec.yaml
is this:dependencies:
It's not fix, it's workaround. As soon as tou run flutter clean
or new developer in your team clone project they need to create empty pubspec.yaml again
Hi all, thank you for your patience. https://github.com/flutter/flutter/pull/68206 should have fixed this issue in master
. If there's still any issues surrounding the pubspec.yaml
issue and build_runner
, please file an issue at https://github.com/flutter/flutter and feel free to cc me in on them.
I don't see this as a workaround tbh. You can maybe do this for a local checkout but the i10n feature is practically not useable with current stable version for larger teams and existing CI pipelines.
Closing the issue here as it seems this is resolved on the flutter side of things - please re-open an issue on the flutter repo as indicated if you are still experiencing issues (or would like to advocate for a hotfix stable release).
@shihaohong any idea on when this fix will be released in Flutter stable? Will it be Flutter 1.23 or it may be released in a hotfix?
I solve it installing in my dev_dependencies this package:
I am still having this problem. None of the above works for me.
I am still having this problem. None of the above works for me.
For me too.
I am still having this problem. None of the above works for me.
@shihaohong do you know the status here? Are there still issues open on the flutter side?
@jakemac53 I think this works fine as expected. I don't know much about recent comments saying that's not working.
It should be working as expected. The most recent comments seem to be spam.
Edit: For anyone still facing the same issue and the fix hasn't resolved your problem, please file an issue in the Flutter repo and tag me in it. Thank you!
Having the same issue:
Unhandled exception: Bad state: Unable to generate package graph, no
.../.dart_tool/flutter_gen/pubspec.yamlfound.
Edit. I had a typo in my l10n.yaml file name, it works for me now!
Having the same issue:
Unhandled exception: Bad state: Unable to generate package graph, no
.../.dart_tool/flutter_gen/pubspec.yamlfound.
Same for me.
Had the same issue with Flutter 1.22.5 and l10n package - the workaround with pubspec.yaml in the ...dart_tool\flutter_gen\ worked. I actually copied the project's main pubspec.yaml there. Other methods described in this thread were not successful.
I removed the
l10n.yaml
and the problem was still there.The problem error disappears when I remove
generate: true
frompubspec.yaml
. May this information help?
thank you, i'm remove generate:true and it run
I had the same problem.
I resolved it following explanations for "flutter_gen" package: https://pub.dev/packages/flutter_gen/install
So simply by adding "flutter_gen: ^1.3.1" in the "pubspec.yaml" dependencies :
`
dependencies: flutter: sdk: flutter flutter_gen: ^1.3.1 auto_route: ^0.6.9 ...
dev_dependencies:
build_runner: ^1.11.1 auto_route_generator: ^0.6.10
flutter: generate: true
uses-material-design: true
`
Then after I did this:
flutter packages pub run build_runner build
Now I have another error but this one :-) ` [INFO] Generating build script... [INFO] Generating build script completed, took 505ms
[INFO] Creating build script snapshot...... [INFO] Creating build script snapshot... completed, took 9.5s
[INFO] Initializing inputs [INFO] FlutterGen Loading ... pubspec.yaml [INFO] Generated: /Users/myhome/Documents/GIT/myproject/lib/gen/assets.gen.dart [INFO] Generated: /Users/myhome/Documents/GIT/myproject/lib/gen/fonts.gen.dart [INFO] FlutterGen finished. [INFO] Building new asset graph... [INFO] Building new asset graph completed, took 487ms
[INFO] Checking for unexpected pre-existing outputs.... [INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[INFO] Running build...
[WARNING] auto_route_generator:autoRouteGenerator on test/widget_test.dart:
Your current analyzer
version may not fully support your current SDK version.
Please try upgrading to the latest analyzer
by running flutter packages upgrade
.
Analyzer language version: 2.12.0 SDK language version: 2.13.0
If you are getting this message and have the latest analyzer please file an issue at https://github.com/dart-lang/sdk/issues/new with the title "No published analyzer available for language version 2.13.0". Please search the issue tracker first and thumbs up and/or subscribe to existing issues if present to avoid duplicates. `
flutter gen-l10n
solved for me
I had another problem trying to use the package "easy_localization". For "flutter channel stable" I had to use the 3.0.0 version of this package. I don't remember exactly but I think I should comment "flutter_gen" because a compatibility problem.
After several modifications in my code I tried to generate again the routes for the package "auto_route". Then I had this error:
✗ flutter packages pub run build_runner build
Unhandled exception:
Bad state: Unable to generate package graph, no /Users/myhome/Documents/GIT/myproject/.dart_tool/flutter_gen/pubspec.yaml
found.
I solve it installing in my dev_dependencies this package:
It worked
I still have this problem with build_runner 1.12.2 :(
Hello devs, I think I have come up with a solution to the riddle.
Although it is written in the official Flutter documentation for internationalization, package intl
cannot generate boilerplate code (such as messages_*.dart or l10n.dart) by just running your app. An additional command line is required to generate necessary files, as it is written at the bottom of the official documentation. Unfortunately, package intl_translation
is required for that and, of course, at the moment there are conflicts between the latest versions of intl
and intl_translation
.
At this point, we have identified two use cases:
If you don't need the files, just don't allow their generation:
false
the generate flag in your pubspec.yaml file (as suggested by https://github.com/dart-lang/build/issues/2835#issuecomment-702511142)flutter clean
your environmentflutter pub get
your dependenciesflutter run
your application, and don't forget flutter pub run build_runner build
if neededIf you need the precious boilerplate code, and you're using the intl
package just for it, then you can safely remove it and replace it with intl_utils
. Although intl_utils
is not mentioned in the official Flutter documentation (which I think needs to be polished a little), and is not an official Flutter package, it represents an ad-hoc solution for this specific problem and it is also null-safety enabled.
If you're willing to use it instead of intl
+build_runner
, then:
intl
from your pubspec.yaml filefalse
the generate flag in your pubspec.yaml file (as suggested by https://github.com/dart-lang/build/issues/2835#issuecomment-702511142)build_runner
from your pubspec.yaml file, if you're not using it to generate anything elseintl_utils
to your pubspec.yaml fileflutter_intl:
enabled: true
class_name: AppLocalization
main_locale: en_US
arb_dir: lib/localization
output_dir: lib/localization/generated
flutter clean
your environmentflutter pub get
your dependenciesflutter pub run intl_utils:generate
{
"label": "l10n generation",
"type": "shell",
"command": "-Command",
"args": [
"flutter",
"pub",
"run",
"intl_utils:generate",
],
}
Hope this helps some lost dev, while waiting for an official Flutter solution. ☺️
I started seeing this issue again when I switched my l10n.yaml file to say:
synthetic-package: false
It no longer generates a synthetic package, but some other part of flutter seems to think that there must be a synthetic package and fails because it cannot find its pubspec.yaml file
The issue came back when generate: true
in pubspec.yml
with synthetic-package: false
in i10n.yml
.
It is useful when build a library with l10n
support, when I want all the generated code in my lib folder rather than a synth project
, but clearly build_tool
would think flutter_gen
is still a thing, so when it try to find that direct not even exists, it breaks the whole build.
I can confirm, that issue is still present with generate: true
and synthetic-package: false
. Is there any workaround other than disabling autogeneration?
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5 20G71 darwin-x64, locale pl-PL)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] IntelliJ IDEA Community Edition (version 2021.1.3)
[✓] VS Code (version 1.58.2)
[✓] Connected device (2 available)
• No issues found!
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 :/
build_runner: ^1.10.3
flutter packages pub run build_runner build
:flutter doctor -v
: