Flutter 2 个月后突然无法构建应用

Posted

技术标签:

【中文标题】Flutter 2 个月后突然无法构建应用【英文标题】:Flutter suddenly fails to build app after 2 months 【发布时间】:2021-05-06 20:19:10 【问题描述】:

我大约 2 个月前构建了一个 Flutter 应用,效果很好,并在 App Store 和 Play Store 上获得了批准。

这几天我正在尝试向应用程序添加新功能,但由于某种原因,Flutter 无法在 ios 模拟器和 android 模拟器上运行该应用程序。

我收到以下错误消息:

安卓

Launching lib/main.dart on sdk gphone x86 arm in debug mode...
lib/main.dart:1
../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/extended_image-1.5.0/lib/src/extended_image.dart:785:44: Error: No named parameter with the name 'nullOk'.
    _invertColors = MediaQuery.of(context, nullOk: true)?.invertColors ??
                                           ^^^^^^
../../../../../../Developer/flutter/packages/flutter/lib/src/widgets/media_query.dart:818:25: Context: Found this candidate, but the arguments don't match.
  static MediaQueryData of(BuildContext context) 
                        ^^
../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:1111:7: Info: Struct 'ENUMLOGFONTEX' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.
class ENUMLOGFONTEX extends Struct 

      ^
../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:2835:7: Info: Struct 'BLUETOOTH_PIN_INFO' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.
class BLUETOOTH_PIN_INFO extends Struct 
      ^
../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:2960:7: Info: Struct 'EXCEPINFO' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.
class EXCEPINFO extends Struct 
      ^
../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:2966:7: Info: Struct 'PROPERTYKEY' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.
class PROPERTYKEY extends Struct 
      ^
../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:2973:7: Info: Struct 'PROPVARIANT' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.

class PROPVARIANT extends Struct 
      ^
../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:2978:7: Info: Struct 'SAFEARRAY' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.
class SAFEARRAY extends Struct 

iOS

Launching lib/main.dart on iPhone 11 in debug mode...
lib/main.dart:1
Xcode build done.                                           24.8s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **
Xcode's output:
↳
    gRPC-Core-camshfbxfmecuqamkwvicvcxlaiu
    ../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/extended_image-1.5.0/lib/src/extended_image.dart:785:44: Error: No named parameter with the name 'nullOk'.
        _invertColors = MediaQuery.of(context, nullOk: true)?.invertColors ??
                                               ^^^^^^
    ../../../../../../Developer/flutter/packages/flutter/lib/src/widgets/media_query.dart:818:25: Context: Found this candidate, but the arguments don't match.
      static MediaQueryData of(BuildContext context) 
                            ^^
    ../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:1111:7: Info: Struct 'ENUMLOGFONTEX' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.
    class ENUMLOGFONTEX extends Struct 
          ^
    ../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:2835:7: Info: Struct 'BLUETOOTH_PIN_INFO' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.
    class BLUETOOTH_PIN_INFO extends Struct 
          ^
    ../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:2960:7: Info: Struct 'EXCEPINFO' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.
    class EXCEPINFO extends Struct 
          ^
    ../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:2966:7: Info: Struct 'PROPERTYKEY' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.
    class PROPERTYKEY extends Struct 
          ^
    ../../../../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.4+1/lib/src/structs.dart:2973:7: Info: Struct 'PROPVARIANT' is empty. Support for empty structs is deprecated and will be removed in the next stable version of Dart. Use Opaque instead.

我已尝试更新 pubsapec.yaml 文件中的所有依赖项,但也没有用。

有谁知道为什么 Flutter 无法构建应用程序?我真的不明白为什么。

非常感谢!

【问题讨论】:

似乎您正在使用的插件已更改如果您有关于上次成功构建应用程序时使用的插件版本的信息 - 您只能为插件设置一个版本(不带 ^)并尝试再次构建应用程序。如果您没有关于插件版本的信息,您可以手动逐步迁移应用程序。 我在更新我的 flutter-dev 版本后遇到了这个问题,但它可以编译并运行。 【参考方案1】:

你改变了你的颤振版本吗?您似乎遇到了与 null 安全迁移有关的重大更改。

您可以尝试使用.maybeOf(context) 而不是.of(context, nullOk: true);

我还应该说,因为它看起来像库,所以你需要确保你的 Flutter 版本与这些库在 null 安全性方面所期望的版本相匹配。

有关更改的详细信息,请参阅以下文档。 https://docs.google.com/document/d/1LKBL0S1uyhACDiUXILhLKFZH8Cpl_w3mXjHgaE8_--U/edit#heading=h.pub7jnop54q0

https://github.com/flutter/website/pull/4921/files

【讨论】:

以上是关于Flutter 2 个月后突然无法构建应用的主要内容,如果未能解决你的问题,请参考以下文章

FAILURE:构建失败并出现异常 (Flutter)

当我在 android studio 上运行 Flutter 应用程序“无法初始化类 org.codehaus”时,突然出现此故障

Gradle 在构建 Flutter 应用程序时突然开始报错

Flutter 使用 C/C++ 代码构建 - 示例?

我们想研发一个机器学习框架,6 个月后失败了

2结帐长期令牌或在 1 个月后开始 1 年定期计费