Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter pub run build_runner build failed

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

like image 696
Smeegol Avatar asked Sep 20 '19 07:09

Smeegol


2 Answers

Try this.

flutter pub get && flutter pub run build_runner build --delete-conflicting-outputs
like image 111
VasilKanev Avatar answered Nov 05 '22 10:11

VasilKanev


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
like image 35
Noorus Khan Avatar answered Nov 05 '22 10:11

Noorus Khan