Reputation: 2098
flutter version:
flutter_macos_v1.9.1+hotfix.2-stable
create new project in terminal:
flutter create myapp
open vscode, edit pubspec.yaml
:
dependencies:
json_annotation: ^3.0.0
dev_dependencies:
build_runner: ^1.7.0
json_serializable: ^3.2.2
get packages in terminal:
flutter pub get
new /lib/user.dart
and filling below:
import 'package:json_annotation/json_annotation.dart';
part 'user.g.dart';
@JsonSerializable()
class User extends Object {
@JsonKey(name: 'seed')
String seed;
@JsonKey(name: 'results')
int results;
@JsonKey(name: 'page')
int page;
@JsonKey(name: 'version')
String version;
User(
this.seed,
this.results,
this.page,
this.version,
);
factory User.fromJson(Map<String, dynamic> srcJson) =>
_$UserFromJson(srcJson);
Map<String, dynamic> toJson() => _$UserToJson(this);
}
run flutter pub run build_runner build
in terminal:
[INFO] Generating build script...
[INFO] Generating build script completed, took 321ms
[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 10.4s
[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 698ms
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 2ms
[INFO] Running build...
[SEVERE] json_serializable:json_serializable on lib/user.dart:
Invalid argument(s): Path must be absolute : dart:core
[SEVERE] json_serializable:json_serializable on lib/main.dart:
Invalid argument(s): Path must be absolute : dart:core
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:
Invalid argument(s): Path must be absolute : dart:core
[INFO] Running build completed, took 1.5s
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 36ms
[SEVERE] Failed after 1.6s
why never succeeded?!
Upvotes: 61
Views: 220178
Reputation: 5
this is the new command - dart run build_runner build --delete-conflicting-outputs
Upvotes: 0
Reputation: 1
this proplem happens with me , if you have analyzer: package try to remove it and make : 1- flutter clean 2- delete pubspec.lock 3- flutter pub get 4- flutter pub run build_runner clean it will work 100% after doing that you can adding you analyzer again and make flutter pub get
Upvotes: 0
Reputation: 121
In my case, when using flutter 3.22.2, the problem was due to overwriting a version of the meta package.
Upvotes: 0
Reputation: 1
dependencies:
retrofit: '>=4.0.0 <5.0.0'
logger: any #for logging purpose
json_annotation: ^4.8.1
dev_dependencies:
retrofit_generator: '>=7.0.0 <8.0.0' // required dart >=2.19
build_runner: '>=2.3.0 <4.0.0'
json_serializable: ^6.6.2
Upvotes: 0
Reputation: 202
add hive_generator
flutter pub get
flutter packages pub run build_runner build
Upvotes: 0
Reputation: 41
I had the same error while running flutter pub run build_runner build --delete-conflicting-outputs
but it was showing this error
Failed to build build_runner:build_runner:
../../../.pub-cache/hosted/pub.dev/watcher-1.0.2/lib/src/constructable_file_system_event.dart:7:57: Error: The class 'FileSystemEvent' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
After trying everything here without success, I simply did a flutter pub get
and everything works well after when I did flutter pub run build_runner build --delete-conflicting-outputs
Upvotes: 0
Reputation: 109
make sure the class name is same with the generated file name. For ex:
part 'User.g.dart';
class User {
}
Upvotes: 0
Reputation: 116
First make sure to maintain small letter and underscore style here:
part 'course_box.g.dart';
Then, run this:
dart pub run build_runner build --delete-conflicting-outputs
It worked for me.
Upvotes: 1
Reputation: 31
In my side I edited the build_runner_core-version package source code outside my flutter project with adding a method to the class BuildForInputLogger in the following code below:
Stream<Level?> get onLevelChanged {
return Stream.empty(); }
And yeah it's worked to me
Upvotes: 0
Reputation: 11
This is working you should definitely try it
I was getting the message "Success after 1.0 seconds with 0 output (0 actions)" when I used it with dart frog. He needed to create a "bin" file and put the factories in it so he could see it. This worked for me!
Upvotes: 1
Reputation: 2704
Looks like flutter clean
is resolving the issue. Try running it before i.e. openApi Generator.
Upvotes: 0
Reputation: 1754
My class name was:
class Game
but my filename was game_model.dart
So you'll need to use:
part 'game_model.g.dart';
You may also need to add hive_generator
dependency.
Upvotes: 0
Reputation: 522
I had the same error. I simply installed the build runner package in pubspec.yaml file like -
dev_dependencies:
build_runner: ^1.3.1
mobx_codegen: ^0.3.9
Upvotes: 1
Reputation: 804
Please create default empty constructor for models class before flutter packages pub run build_runner build
command
Upvotes: 8
Reputation: 2418
I tried with many solutions, But error not gone. flutter packages pub run build_runner watch
command ran with endless log.
I deleted pubspec.lock and ran flutter pub get
and installed dependency again and ran above command. After this error gone.
Upvotes: 31
Reputation: 1820
Update 2020/8/24: seems to break build_runner or json_serializable in version:
Analyzer: 0.39.16
Going back to dart analyzer version:
Analyzer: 0.39.14
fixed it for me. So, something is broken in 0.39.16.
Upvotes: 0
Reputation: 41
I got this to work with the latest build_runner and json_serializable versions after a long process of trying all of the above suggestions: build_runner: ^1.10.2 json_serializable: ^3.4.0 Not sure what ultimately worked, but looks like one of the issues in my case was a slightly outdated dart SDK, so that's one more thing to keep an eye on
Upvotes: 4
Reputation: 1476
add dependency in pubsec.yaml, analyzer: '0.39.14'
flutter clean
flutter pub cache repair
flutter pub run build_runner clean
Then run,
flutter pub run build_runner build
Upvotes: 53
Reputation: 1562
Try this.
flutter pub get && flutter pub run build_runner build --delete-conflicting-outputs
Upvotes: 115
Reputation: 81
I had the same issue, so I just saved the changes first in the class (in your case User
class).
And then I just retried using:
flutter pub run build_runner build
Upvotes: 8
Reputation: 753
It might not be the case in this situation, but I had a similar problem caused by my auto formatter removing this line:
part 'my_class.g.dart';
Once I added that line and ran the command again it worked fine.
Upvotes: 3
Reputation: 131
Looks like Analyzer is breaking it, downgrading to analyzer: 0.38.2
solved it for me.
Source: https://github.com/dart-lang/sdk/issues/38499#issuecomment-533812652
Upvotes: 2
Reputation: 31
I had the same issue.
build_runner 0.9.2
json_serializable 0.5.8+1
json_annotation 0.2.9+1
Upvotes: 2