I am writing a dart source generator that is using json_serializable for some of it models. Initially the source generation was working fine for some time but now when I run dart run build_runner build --delete-conflicting-outputs I am getting error:
[INFO] Generating build script completed, took 410ms [INFO]
Reading cached asset graph completed, took 62ms [INFO] Checking
for updates since last build completed, took 492ms [WARNING]
Invalidating asset graph due to build script update! [INFO]
Cleaning up outputs from previous builds. completed, took 4ms
[INFO] Generating build script completed, took 79ms [WARNING]
Invalidated precompiled build script due to missing asset graph.
[WARNING] lib/settings/config.dart:3:6: Error: Error when reading
'lib/settings/config.g.dart': No such file or directory part
'config.g.dart';
^ lib/settings/config.dart:3:6: Error: Can't use 'lib/settings/config.g.dart' as a part, because it has no 'part of'
declaration. part 'config.g.dart';
^ [INFO] Precompiling build script... completed, took 785ms [SEVERE] Failed to precompile build script
.dart_tool/build/entrypoint/build.dart. This is likely caused by a
misconfigured builder definition.
Here is the dependencies for my package:
dependencies:
path: ^1.8.1
yaml: ^3.1.0
dotenv: ^3.0.0
recase: ^4.0.0
json_annotation: ^4.4.0
code_builder: ^4.1.0
dart_style: ^2.2.1
dev_dependencies:
lints: ^1.0.0
test: ^1.20.1
build_runner: ^2.1.7
json_serializable: ^6.1.3
And build.yaml looks like this:
builders:
map_gen:
import: "package:map_gen/map_gen.dart"
builder_factories: [ "build" ]
build_extensions: { "$lib$": [ ".map.dart" ] }
auto_apply: dependents
build_to: source
I haven't been able to figure out why this is happening or is there any limitation on using source generator for a package that provides its own generators. Is there any way I can resolve this?
Edit
I am using vscode, but I have tried building from terminal and also getting the same error. Even after running flutter clean | dart pub get | dart run build_runner build --delete-conflicting-outputs same error persists.
Current workaround
Currently I am manually creating .g.dart file and adding the part of statement manually, running build_runner after that results in successful source generation. However if I run build_runner again after I have linked generated methods to my code, the .g.dart files are deleted and again I am facing with the same error. I have to repeat this process every time I want source generation.
I faced the exact same issue and got help from the creator of Drift in Dart Build's Gitter chat room. Quoting the solution here:
you can simply create an empty <project_directory>.build.yaml file in your package's directory. This special build.yaml file will only be used when a build is started from the directory of your package. To the build system, it will look like your builders simply don't exist (and thus it won't attempt to compile them). When you run a build from other packages that depend on your builder package, the <project_directory>.build.yaml file is ignored and all your builders are there.
You can refer to how Drift do it here.
Related
I was using ObjectBox without many problems for a while during a development with Flutter, but now the build_runner fails:
The closest change I have made is a Flutter upgrade yesterday to Flutter 2.5.3 along with Dart 2.14.4.
ObjectBox dependencies in pubspec.yaml are:
objectbox: ^1.2.0
objectbox_flutter_libs: any
Now, although the objectbox-model.json file is there, the objectbox.g.dart file is missing and does not get regenerated.
I then tried to run the two example projects give in the official OB documents, but those failed too with similar results (they ran OK before this).
The complete build stack is as follows:'
Microsoft Windows [Version 10.0.19042.1237] (c) Microsoft Corporation. All rights reserved.
D:\learnedfriend>flutter pub run build_runner watch --delete-conflicting-outputs
[INFO] Generating build script...
[INFO] Generating build script completed, took 462ms
[INFO] Setting up file watchers...
[INFO] Setting up file watchers completed, took 11ms
[INFO] Waiting for all file watchers to be ready...
[INFO] Waiting for all file watchers to be ready completed, took 358ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 126ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 6.3s
[INFO] Running build...
[INFO] Running build completed, took 14ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 54ms
[SEVERE] objectbox_generator:generator on lib/$lib$ (cached):
Bad state: lastRelationId 4:6834778133563033891 does not match any standalone relation
[SEVERE] Failed after 85ms
I have found a solution to this problem and am posting it for the benefit of whoever encounters the same issue in future.
You should manually delete the objectbox-model.json file and objectbox.g.dart (if it still exists) and run the command "flutter pub run build_runner watch --delete-conflicting-outputs" at the project folder (without quotes, of course).
Also, it has to be mentioned that, as at the time of writing this post, if ObjectBox is a contemplated choice for your persistence, please be wary that (although it is an excellent package), support for a problem if you get stuck is very low to nil, in stackoverflow. I have not seen more than 2 or 3 contributors and if your question escapes their attention, you are pretty much on your own!
I have added addtional Hive Fields to a Hive type before as needed. I have then deleted .g.dart file and regenerated it with no problems.
This time after added a new Hive Field I have this error and I am not able to understand why
[INFO] Generating build script...
[INFO] Generating build script completed, took 424ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 73ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 968ms
[INFO] Running build...
[INFO] Running build completed, took 21ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 55ms
[SEVERE] hive_generator:hive_generator on lib/main.dart (cached):
This builder requires Dart inputs without syntax errors.
However, package:flutter_app_hive/main.dart (or an existing part) contains the following errors.
main.dart:33:3: Expected to find ';'.
main.dart:33:3: Expected an identifier.
Try fixing the errors and re-running the build.
[SEVERE] Failed after 92ms
pub finished with exit code 1
I have tried flutter clean, flutter pub outdated, pub get, etc... and I keep getting this error.
In my pubspec.yaml I have, this worked just fine until I have added the latest Hive Field.
dependencies:
flutter:
sdk: flutter
hive: ^2.0.2
hive_flutter: ^1.0.0
path_provider: ^2.0.1
curved_navigation_bar: ^0.3.7
video_player: ^1.0.1
font_awesome_flutter: ^8.5.0
badges: ^1.2.0
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.0.1
hive_generator: ^1.1.0
I found an old post about downgrading analyzer, but this then causes problems with the versions I am using.
In the main.dart there isn't an error on line 33:3. it should not have ; as suggested. Again this worked fine before, so I am not sure why it is an issue now. I also commented out the code here and I still get the same error message even with nothing at line 33:3
If I remove the field I added I still get the same error. If I restore the .g.dart file from a backup I can run the app as before.
Any input on this would be appreciated as it's very confusing
Update:
So I tried deleting the model file and completely recreating it and then generating the .g.dart. I get this:
[INFO] Generating build script...
[INFO] Generating build script completed, took 485ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 83ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 1.1s
[INFO] Running build...
[INFO] Running build completed, took 23ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 66ms
[INFO] Succeeded after 102ms with 0 outputs (0 actions)
I have tried keeping the file as it was, added a new Hive Field to a previous Hive Type and adding a Hive type and I get nothing generated.
I haven't changed the existing Hive fields, I know that causes issues. New Hive Fields and Hive Types were given the next number that hadn't been used before.
So I didn't fix the issue, but for a work around I created a new flutter project, copied my code over except any generated files. Then I was able to generate new type adapters after adding new Hive fields and hive types. Maybe something got corrupted in my previous project. Not sure why flutter clean wouldn't fix this. But maybe this will help someone stuck on the same issue.
Set source_gen: 1.0.3 in pubspec.yaml helped in my case.
Currently I'm doing a Flutter application witch uses:
geolocator: ^5.1.4+1
google_maps_flutter: ^0.5.21+7
When I declare both dependencies in "pubspec.yaml" it get a conflict
"FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:preDebugBuild'.
Android dependency 'com.google.android.gms:play-services-tasks' has different version for the compile (16.0.1) and runtime (17.0.0) classpath. You should manually set the same version via DependencyResolution"
I've tryied also by editing gradle.properties with:
android.useAndroidX=true
android.enableJetifier=true
And in "app/build.gradle" added the dependencies as classpath and/or api as needed:
com.google.android.gms:play-services-tasks
Is anyone facing same issue? In case you solved it, what have you done to solve it?
I had exactly the same problem, though using google_maps_flutter0.5.21+8.
I added for every error message the following line to android/app/build.gradle under dependencies. Look then like the following:
dependencies {
...
implementation 'androidx.cursoradapter:cursoradapter:1.0.0'
implementation 'androidx.drawerlayout:drawerlayout:1.0.0'
implementation 'androidx.documentfile:documentfile:1.0.0'
implementation 'androidx.viewpager:viewpager:1.0.0'
implementation 'androidx.arch.core:core-runtime:2.0.0'
implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
implementation 'androidx.fragment:fragment:1.0.0'
implementation 'androidx.core:core:1.1.0'
implementation 'com.google.android.gms:play-services-basement:17.0.0'
implementation 'com.google.android.gms:play-services-base:17.0.0'
}
Hope that helps. If there's a better way please tell. No flutter expert so far.
[edit]
if i run webdev serve in my project there appears
[WARNING] Throwing away cached asset graph because the build phases have changed. This most commonly would happen as a result of adding a new dependency or updating your dependencies.
[INFO] Cleaning up outputs from previous builds. completed, took 6.6s
[INFO] Building new asset graph completed, took 16.7s
[INFO] Checking for unexpected pre-existing outputs. completed, took 3ms
[INFO] Serving `web` on http://127.0.0.1:8080
[WARNING]build_web_compilers:entrypoint on web/main.dart: Skipping compiling retgoo_internal|web/main.dart with ddc because some of its
transitive libraries have sdk dependencies that not supported on this platform:
retgoo_internal|lib/protocol/http_non.dart
https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-skipped-compiling-warnings
[INFO] Running build completed, took 19.0s
[INFO] Caching finalized dependency graph completed, took 473ms
[INFO] Succeeded after 19.5s with 634 outputs (3522 actions)
but when I try to open in the browser just a blank page appears and when I try to start debugging there just launches and a blank page appears too. the launch didn't stop. there is a tutorial for the warning in the build.yaml file, but when I search for a lot of build.yaml files ... which file should I fix?
In your wanrnig message it is clearly stated due to some transitive sdk dependencies the main.dart is not compiled.
[WARNING]build_web_compilers:entrypoint on web/main.dart: Skipping compiling retgoo_internal|web/main.dart with ddc because some of its
transitive libraries have sdk dependencies that not supported on this platform:
retgoo_internal|lib/protocol/http_non.dart
This simply means that none of your flutter related dart code is compiled to javascript. In my limited knowledge, flutter-web does this.
It compiles yout dart code written using flutter framework into javascript.
This means main.dart and other dart files compiled into main.dart.js and other chunks.js files.
Then in the web/index.html this javascript file is loaded, which further creates and handles the new dom elements to be rendered in you page. Some thing like a Single Page Applications created by react or angular.
Once you fix the transitive dependencies in your pubspec.yaml which could have been introduced by any additional libraries you added as depencies, this problem wil be resolved.
Since flutter-web doesn't support any plugins yet this has to be done manually by pulling the sources for the plugins you wish to include, place along your source directories and change the import statements inside them from package:flutter/ to package:flutter_web. This is not trivial but still achievable.
Following this
And using cli
stagehand web-angular
pub get
webdev serve
Output:
[INFO] Setting up file watchers completed, took 25ms
[INFO] Waiting for all file watchers to be ready completed, took 201ms
[INFO] Building new asset graph completed, took 1.2s
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[SEVERE] angular_components|scss_builder on package:angular_components/material_ripple/material_ripple.scss:
Error: Can't find stylesheet to import.
#import 'const/global',
^^^^^^^^^^^^^^
/private/var/folders/3p/8z23nlbs20qf291vlhjy1l0h0000gn/T/scratch_spaceuuJ2f0/packages/angular_components/css/material/_material.scss 19:9 #import
/private/var/folders/3p/8z23nlbs20qf291vlhjy1l0h0000gn/T/scratch_spaceuuJ2f0/packages/angular_components/material_ripple/material_ripple.scss 5:9 root stylesheet
[SEVERE] angular_components|scss_builder on package:angular_components/material_slider/material_slider.scss:
And the list goes on with a lot more
Do you know how to fix this?
This is a known issue. A work around is to add the following dependency override to your project's pubspec.yaml:
dependency_overrides:
sass: 1.3.2