book icon indicating copy to clipboard operation
book copied to clipboard

关于flutter pub run build_runner build

Open tim0991 opened this issue 2 years ago • 1 comments

修改了entity HotBook.dart 对象属性之后 重新生成HotBook.g.dart

发现build_runner被注释,尝试使用原版本build报错

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

[WARNING] Deleted previous snapshot due to missing asset graph.
[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 15.9s

[INFO] There was output on stdout while compiling the build script snapshot, run with `--verbose` to see it (you will need to run a `clean` first to re-snapshot).

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

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

[INFO] Running build...
[INFO] 1.2s elapsed, 11/26 actions completed.
[SEVERE] json_serializable:json_serializable on lib/entity/ReadPage.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/ReadPage.dart:7:7
  ╷
7 │ class ReadPage {
  │       ^^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/GBook.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/GBook.dart:6:7
  ╷
6 │ class GBook {
  │       ^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/ChapterList.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/ChapterList.dart:7:7
  ╷
7 │ class ChapterList {
  │       ^^^^^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/TextLine.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/TextLine.dart:6:7
  ╷
6 │ class TextLine {
  │       ^^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/BookVotec.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/BookVotec.dart:4:7
  ╷
4 │ class BookVotec {
  │       ^^^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/BookTag.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/BookTag.dart:6:7
  ╷
6 │ class BookTag {
  │       ^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/DetailVO.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/DetailVO.dart:6:7
  ╷
6 │ class DetailVO {
  │       ^^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/Info.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/Info.dart:6:7
  ╷
6 │ class Info {
  │       ^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/BookInfo.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/BookInfo.dart:8:7
  ╷
8 │ class BookInfo {
  │       ^^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/Chapter.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/Chapter.dart:6:7
  ╷
6 │ class Chapter {
  │       ^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/TopBook.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/TopBook.dart:6:7
  ╷
6 │ class TopBooks {
  │       ^^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/Book.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/Book.dart:6:7
  ╷
6 │ class Book {
  │       ^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/ParseContentConfig.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/ParseContentConfig.dart:6:7
  ╷
6 │ class ParseContentConfig {
  │       ^^^^^^^^^^^^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/SearchItem.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/SearchItem.dart:6:7
  ╷
6 │ class SearchItem {
  │       ^^^^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/HotBook.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/HotBook.dart:6:7
  ╷
6 │ class HotBook {
  │       ^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/TextPage.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/TextPage.dart:7:7
  ╷
7 │ class TextPage {
  │       ^^^^^^^^
  ╵
[SEVERE] json_serializable:json_serializable on lib/entity/TopResult.dart:

Generator cannot target libraries that have not been migrated to null-safety.
package:book/entity/TopResult.dart:7:7
  ╷
7 │ class TopResult {
  │       ^^^^^^^^^
  ╵
[INFO] Running build completed, took 2.7s

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

[SEVERE] Failed after 2.8s

那我升版本或者降到无null safety版本 之后再运行build报错

Failed to build build_runner:build_runner:
/usr/local/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:258:50: Error: The property 'displayString' is defined in multiple extensions for 'TargetKind' and neither is more specific.
 - 'TargetKind' is from 'package:meta/meta_meta.dart' ('/usr/local/flutter/.pub-cache/hosted/pub.flutter-io.cn/meta-1.7.0/lib/meta_meta.dart').
Try using an explicit extension application of the wanted extension or hiding unwanted extensions from scope.
        var kindNames = kinds.map((kind) => kind.displayString).toList()
                                                 ^^^^^^^^^^^^^
/usr/local/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:1950:14: Context: This is one of the extension members.
  String get displayString {
             ^^^^^^^^^^^^^
/usr/local/flutter/.pub-cache/hosted/pub.flutter-io.cn/meta-1.7.0/lib/meta_meta.dart:91:14: Context: This is one of the extension members.
  String get displayString {
             ^^^^^^^^^^^^^
/usr/local/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:260:36: Error: The getter 'commaSeparatedWithOr' isn't defined for the class 'List<dynamic>'.
 - 'List' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'commaSeparatedWithOr'.
        var validKinds = kindNames.commaSeparatedWithOr;
                                   ^^^^^^^^^^^^^^^^^^^^

请问有没有保持版本可以编译通过的办法

flutter pub outdated --mode=null-safety 
Showing dependencies that are currently not opted in to null-safety.
[✗] indicates versions without null safety support.
[✓] indicates versions opting in to null safety.

Package Name               Current       Upgradable    Resolvable    Latest

direct dependencies:
flutter_statusbar_manager  ✗2.0.0 (git)  ✗2.0.0 (git)  ✗2.0.0 (git)  ✗2.0.0 (git)
flutter_swiper             ✗1.1.6        ✗1.1.6        ✗1.1.6        ✗1.1.6

dev_dependencies:
build_runner               ✗1.12.2       ✗1.12.2       ✓2.1.5        ✓2.1.5

或者如果要升级到null-safety的话 flutter_statusbar_manager flutter_swiper这两个package又好像没办法直接升 有办法吗

tim0991 avatar Nov 09 '21 07:11 tim0991

build_runner 可以弃用 通过接口获取json数据 https://jsontodart.com/ 目前项目在重构 现在这些代码参考下就可以

leetomlee123 avatar Nov 29 '21 06:11 leetomlee123