-1

我想在 github 操作中运行此命令以在颤振(2.x)中生成 json 可序列化文件,我正在使用json_serializable库:

flutter pub run build_runner build --delete-conflicting-outputs

但是这个命令运行失败,我没有从日志输出中找到任何错误消息,日志如下所示:

Run flutter pub run build_runner build --delete-conflicting-outputs
[INFO] Generating build script...
[INFO] Generating build script completed, took 666ms

[INFO] Precompiling build script......
[INFO] Precompiling build script... completed, took 8.5s

[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 913ms

[INFO] Checking for unexpected pre-existing outputs....
[INFO] Deleting 10 declared outputs which already existed on disk.
[INFO] Checking for unexpected pre-existing outputs. completed, took 4ms

[INFO] Running build...
[INFO] Generating SDK summary...
[INFO] 4.5s elapsed, 0/16 actions completed.
[INFO] Generating SDK summary completed, took 4.4s

[INFO] 5.5s elapsed, 0/16 actions completed.
[INFO] 6.5s elapsed, 0/16 actions completed.
[INFO] 7.5s elapsed, 0/16 actions completed.
[INFO] 8.6s elapsed, 0/16 actions completed.
[INFO] 9.6s elapsed, 0/16 actions completed.
[INFO] 10.7s elapsed, 0/16 actions completed.
[INFO] 11.8s elapsed, 0/16 actions completed.
[INFO] 12.9s elapsed, 0/16 actions completed.
[INFO] 14.0s elapsed, 0/16 actions completed.
Warning:  No actions completed for 15.0s, waiting on:
  - json_serializable:json_serializable on lib/main.dart
  - json_serializable:json_serializable on lib/part/part.dart
  - json_serializable:json_serializable on lib/material/hero.dart
  - json_serializable:json_serializable on lib/material/app.dart
  - json_serializable:json_serializable on lib/material/user.dart
  .. and 11 more

[INFO] 25.7s elapsed, 0/16 actions completed.
[SEVERE] json_serializable:json_serializable on lib/material/button.dart:

The version constraint "any" on json_annotation allows versions before 4.3.0 which is not allowed.
[INFO] 27.7s elapsed, 1/17 actions completed.
[INFO] 33.0s elapsed, 6/22 actions completed.
[INFO] 34.1s elapsed, 28/43 actions completed.
[INFO] 35.1s elapsed, 37/53 actions completed.
[INFO] 36.1s elapsed, 42/57 actions completed.
[SEVERE] json_serializable:json_serializable on test/pages/my_collection_page_test.dart:

The version constraint "any" on json_annotation allows versions before 4.3.0 which is not allowed.
[INFO] 38.6s elapsed, 54/70 actions completed.
[INFO] 39.7s elapsed, 63/77 actions completed.
[INFO] 40.8s elapsed, 87/103 actions completed.
[INFO] 41.9s elapsed, 115/129 actions completed.
Warning:  json_serializable:json_serializable on lib/repository/objects/music_count.dart:
The constructor parameter for `artistCount` has a default value `0`, but the `JsonKey.defaultValue` value `0` will be used for missing or `null` values in JSON decoding.
Warning:  json_serializable:json_serializable on lib/repository/objects/music_count.dart:
The constructor parameter for `djRadioCount` has a default value `0`, but the `JsonKey.defaultValue` value `0` will be used for missing or `null` values in JSON decoding.
Warning:  json_serializable:json_serializable on lib/repository/objects/music_count.dart:
The constructor parameter for `mvCount` has a default value `0`, but the `JsonKey.defaultValue` value `0` will be used for missing or `null` values in JSON decoding.
Warning:  json_serializable:json_serializable on lib/repository/objects/music_count.dart:
The constructor parameter for `createDjRadioCount` has a default value `0`, but the `JsonKey.defaultValue` value `0` will be used for missing or `null` values in JSON decoding.
Warning:  json_serializable:json_serializable on lib/repository/objects/music_count.dart:
The constructor parameter for `createdPlaylistCount` has a default value `0`, but the `JsonKey.defaultValue` value `0` will be used for missing or `null` values in JSON decoding.
Warning:  json_serializable:json_serializable on lib/repository/objects/music_count.dart:
The constructor parameter for `subPlaylistCount` has a default value `0`, but the `JsonKey.defaultValue` value `0` will be used for missing or `null` values in JSON decoding.
[INFO] 43.7s elapsed, 166/182 actions completed.
[INFO] 44.8s elapsed, 199/215 actions completed.
[INFO] 45.8s elapsed, 232/246 actions completed.
[INFO] 46.9s elapsed, 264/280 actions completed.
[INFO] 47.9s elapsed, 404/405 actions completed.
Warning:  source_gen:combining_builder on lib/model/fav_music.dart:
fav_music.g.dart must be included as a part directive in the input library with:
    part 'fav_music.g.dart';
[INFO] Running build completed, took 48.3s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 308ms

[SEVERE] Failed after 48.6s
pub finished with exit code 1
Error: Process completed with exit code 1.

哪里出了问题?我应该怎么做才能解决这个问题?

4

1 回答 1

1

您可以尝试将此行添加到文件中fav_music.dart吗?

part 'fav_music.g.dart';

例子:

part 'fav_music.g.dart';
@JsonSerializable()
class FavMusic {
  int status;

于 2021-10-19T15:48:22.220 回答