改造生成器构建失败

Posted

技术标签:

【中文标题】改造生成器构建失败【英文标题】:Retrofit generator build failed 【发布时间】:2021-08-28 22:36:46 【问题描述】:

我更新了我的插件并得到了改造错误,所以我删除了 api_service.g.dart 并再次尝试重新生成该文件,但我无法构建此文件,请帮助我。

环境:sdk: ">=2.7.0

依赖关系:颤动: sdk:颤振提供者:^5.0.0 改造:^2.0.0 json_annotation:^4.0.0 记录器:^1.0.0-nullsafety.0 pretty_dio_logger:^1.1.1 dio:^4.0.0 razorpay_flutter:^1.2.6 内置值:^8.0.6 Cupertino_icons:^1.0.2 flutter_svg:^0.22.0 simple_animations: ^3.1.1 shared_preferences: ^2.0.6 http: ^0.13.3 flutter_staggered_grid_view: ^0.4.0-nullsafety.3 #fluttertoast: ^4.0.0 可重新排序:^0.4.1 bubble_bottom_bar:^1.2.0 连接性:^3.0.4 webview_flutter:^2.0.2 charts_flutter: ^0.10.0 fcharts:^0.0.11 分享:^2.0.0 package_info:^2.0.2 启动审查:^3.0.1 加载动画:^2.1.0 获取: ^4.0.0-nullsafety.2 percent_indicator: ^3.3.0-nullsafety.1 url_launcher:^6.0.6 firebase_core:^1.3.0 firebase_crashlytics: ^2.0.6 新版本:

dev_dependencies:颤振测试: sdk:颤振改造生成器:^2.0.0+1 json_serializable:^4.0.2 build_runner:^2.0.4 built_value_generator:^8.0.6

飞镖文件

   part 'api_service.g.dart';

@RestApi(baseUrl: "https://example.com/")
abstract class ApiService 
  factory ApiService(Dio dio, String baseUrl) = _ApiService;

  static ApiService create() 
    final dio = Dio();
    dio.interceptors.add(PrettyDioLogger());
    dio.interceptors.clear();
    return ApiService(dio);
  

  @POST("project/id")
  Future<String> addProject(@Path() String id,
      @Body() Map<String, dynamic> body,);

我得到的错误

chetanmahajan@chetans-mini things_linker % flutter pub run build_runner build
[INFO] Generating build script...
[INFO] Generating build script completed, took 540ms

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

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

[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms

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

[INFO] 4.1s elapsed, 0/16 actions completed.
[INFO] 5.2s elapsed, 0/16 actions completed.
[INFO] 6.3s elapsed, 0/16 actions completed.
[INFO] 7.3s elapsed, 0/16 actions completed.
[INFO] 8.4s elapsed, 1/17 actions completed.
[INFO] 15.1s elapsed, 3/19 actions completed.
[INFO] 16.1s elapsed, 3/19 actions completed.
[INFO] 17.1s elapsed, 3/19 actions completed.
[INFO] 19.0s elapsed, 3/19 actions completed.
[INFO] 20.0s elapsed, 33/49 actions completed.
[SEVERE] retrofit_generator:retrofit on lib/api_service/api_service.dart:

Could not format because the source could not be parsed:

line 59, column 26 of .: A function body must be provided.
   ╷
59 │ @override Future<String*>* addDevice(id, body) async   const _extra = <String, dynamic>;
   │                          ^
   ╵
line 59, column 28 of .: A function body must be provided.
   ╷
59 │ @override Future<String*>* addDevice(id, body) async   const _extra = <String, dynamic>;
   │                            ^^^^^^^^^
   ╵
line 98, column 18 of .: Expected to find '>'.
   ╷
98 │ @override Future<String*>* sensorDay(id) async   const _extra = <String, dynamic>;
   │                  ^^^^^^
   ╵
line 40, column 26 of .: Operator declarations must be preceded by the keyword 'operator'.
   ╷
40 │ @override Future<String*>* getProjects(id) async   const _extra = <String, dynamic>;
   │                          ^
   ╵
line 86, column 11 of .: Methods must have an explicit list of parameters.
   ╷
86 │ @override Future<String*>* sensorHour(id) async   const _extra = <String, dynamic>;
   │           ^^^^^^
   ╵
line 92, column 26 of .: Methods must have an explicit list of parameters.
   ╷
92 │ @override Future<String*>* sensorThreeHours(id) async   const _extra = <String, dynamic>;
   │                          ^
   ╵
line 46, column 28 of .: A function body must be provided.
   ╷
46 │ @override Future<String*>* updateDevice(id, body) async   const _extra = <String, dynamic>;
   │                            ^^^^^^^^^^^^
   ╵
line 53, column 26 of .: A function body must be provided.
   ╷
53 │ @override Future<String*>* deleteDevice(id) async   const _extra = <String, dynamic>;
   │                          ^
   ╵
line 53, column 28 of .: A function body must be provided.
   ╷
53 │ @override Future<String*>* deleteDevice(id) async   const _extra = <String, dynamic>;
   │                            ^^^^^^^^^^^^
   ╵
line 46, column 26 of .: A function body must be provided.
   ╷
46 │ @override Future<String*>* updateDevice(id, body) async   const _extra = <String, dynamic>;
   │                          ^
   ╵
(128 more errors...)
[INFO] Running build completed, took 21.4s

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

[SEVERE] Failed after 21.5s
pub finished with exit code 1

请帮忙。 提前致谢。

【问题讨论】:

我找到了一个解决方案,只需要更改项目环境即可。如果要更新旧项目。环境:sdk:">=2.12.0 【参考方案1】:

改变

环境:sdk: ">=2.X.0

环境:sdk: ">=2.12.0

【讨论】:

除了这样做没有别的选择了吗?我不想将我的项目升级为强制空安全。

以上是关于改造生成器构建失败的主要内容,如果未能解决你的问题,请参考以下文章

Maven Cucumber Reports 中构建失败时不生成报告

任务应用程序执行失败生成调试构建配置

Core Data 代码生成导致构建失败

为spring boot应用程序生成war包时maven构建失败?

十个网络优化改造案例之四--NAS区域网络第一次改造

Angular 10.2 构建:本地化包生成失败:无法读取未定义的属性“值”