How to fix Flutter build_runner error: Failed to precompile build_runner:build_runner:
How to fix Flutter build_runner error: Failed to precompile build_runner:build_runner:
我正在处理两个 Flutter 项目,其中一个已经迁移到空安全并使用 Flutter 2.0.5。第二个项目,即导致问题的项目,尚未迁移到空安全并使用 Flutter 1.22.6。只需重命名 Flutter SDK 文件夹即可切换项目。
现在的问题是 build_runner
仅适用于 Flutter 2.0.5。从 Flutter 1.22.6 项目内部调用 flutter pub run build_runner build
时失败
带有以下错误消息:
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}) =>
奇怪的是所有这些错误都在项目之外。
调用 flutter clean
和 flutter pub cache repair
无效。所以问题是,需要做什么才能让 build_runner
在(现已过时的)Flutter version 1.22.6
上工作?
非常欢迎您的建议,谢谢!
由于所需的第三方库阻止迁移到空安全,唯一的解决方案是通过从生成的 json 切换到手写的来消除 build_runner。
与其说是解决方案,不如说是解决方法,但它已经足够了。
我正在处理两个 Flutter 项目,其中一个已经迁移到空安全并使用 Flutter 2.0.5。第二个项目,即导致问题的项目,尚未迁移到空安全并使用 Flutter 1.22.6。只需重命名 Flutter SDK 文件夹即可切换项目。
现在的问题是 build_runner
仅适用于 Flutter 2.0.5。从 Flutter 1.22.6 项目内部调用 flutter pub run build_runner build
时失败
带有以下错误消息:
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}) =>
奇怪的是所有这些错误都在项目之外。
调用 flutter clean
和 flutter pub cache repair
无效。所以问题是,需要做什么才能让 build_runner
在(现已过时的)Flutter version 1.22.6
上工作?
非常欢迎您的建议,谢谢!
由于所需的第三方库阻止迁移到空安全,唯一的解决方案是通过从生成的 json 切换到手写的来消除 build_runner。
与其说是解决方案,不如说是解决方法,但它已经足够了。