How to fix Flutter build_runner error: Failed to precompile build_runner:build_runner:

771 views Asked by At

I'm working on two Flutter projects, one of them has already been migrated to null safety and uses Flutter 2.0.5. The second project, the one that causes the issues, is not yet migrated to null safety and uses Flutter 1.22.6. Switching projects is done by just renaming the Flutter SDK folder.

Now the problem is that build_runner only works for Flutter 2.0.5. When calling flutter pub run build_runner build from inside the Flutter 1.22.6 project, it fails with the following error messages:

Failed to precompile build_runner:build_runner:
../../../Flutter%20SDK/flutter/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.1.0/lib/src/multi_headers.dart:97:8: Error: The method 'MultiHeaders.add' has fewer named arguments than those of overridden method 'HttpHeaders.add'.
  void add(String name, Object value) {
       ^
org-dartlang-sdk:///sdk/lib/_http/http.dart:698:8: Context: This is the overridden method ('add').
  void add(String name, Object value,
       ^
../../../Flutter%20SDK/flutter/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.1.0/lib/src/multi_headers.dart:129:8: Error: The method 'MultiHeaders.set' has fewer named arguments than those of overridden method 'HttpHeaders.set'.
  void set(String name, Object value) {
       ^
org-dartlang-sdk:///sdk/lib/_http/http.dart:707:8: Context: This is the overridden method ('set').
  void set(String name, Object value,
       ^
../../../Flutter%20SDK/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.11.0/lib/src/entrypoint/runner.dart:23:31: Error: No named parameter with the name 'usageLineLength'.
  final argParser = ArgParser(usageLineLength: lineLength);
                              ^^^^^^^^^^^^^^^
../../../Flutter%20SDK/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.4.4/lib/src/arg_parser.dart:43:11: Context: Found this candidate, but the arguments don't match.
  factory ArgParser({bool allowTrailingOptions: true}) =>
          ^
../../../Flutter%20SDK/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.11.0/bin/src/commands/clean.dart:18:31: Error: No named parameter with the name 'usageLineLength'.
  final argParser = ArgParser(usageLineLength: lineLength);
                              ^^^^^^^^^^^^^^^
../../../Flutter%20SDK/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.4.4/lib/src/arg_parser.dart:43:11: Context: Found this candidate, but the arguments don't match.
  factory ArgParser({bool allowTrailingOptions: true}) =>
          ^
../../../Flutter%20SDK/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.11.0/bin/src/commands/generate_build_script.dart:18:31: Error: No named parameter with the name 'usageLineLength'.
  final argParser = ArgParser(usageLineLength: lineLength);
                              ^^^^^^^^^^^^^^^
../../../Flutter%20SDK/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.4.4/lib/src/arg_parser.dart:43:11: Context: Found this candidate, but the arguments don't match.
  factory ArgParser({bool allowTrailingOptions: true}) =>

Oddly enough all of these errors are outside the project. Calling flutter clean and flutter pub cache repair has no effect. So the question is, what needs to be done to get build_runner working on (the now obsolete) Flutter version 1.22.6? Your advise is very much welcome, Thank you!

1

There are 1 answers

0
SePröbläm On BEST ANSWER

Because a required third party library prevented migrating to null safety, the only solution was to eliminate build_runner by switching from generated json to hand written one.

More a workaround than a solution, but it sufficed.