升级到 macOS Big Sur 后,任务 ':app:compileFlutterBuildDebug' 执行失败

时间:2021-03-06 22:32:43

标签: flutter dart build.gradle macos-big-sur build-error

上周我设法从 Catalina 升级到 Big Sur。我希望你有一些想法来帮助我解决我的问题。提前致谢。

我有一个 Flutter 项目,我已经维护了几个月,在更新之前在 Android 和 iOS 上都可以运行。我们通过 GIT 共享项目,一切都适用于团队中的其他三个人。现在,不幸的是,我在 Android 和 iOS 上都遇到了 BUILD FAILED。

当我升级到 Big Sur 后出现错误时,我也决定更新所有 Flutter 组件。

前面有一件事。当我开始一个新的 Flutter 项目时,我可以在 Android 和 iOS 中构建它。所以这不是一个根本问题。

设置

  • MacBook Pro 2019,macOS 11.2.2(当前版本)
  • VS Code 1.54.1(当前版本)

颤振医生

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.1, on macOS 11.2.2 20D80 darwin-x64, locale
    de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.54.1)
[✓] Connected device (2 available)

• No issues found!

Android 错误

Launching lib/main.dart on AOSP on IA Emulator in debug mode...
lib/main.dart:1
../../../flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/delegate_widget.dart:194:18: Error: Superclass has no method named 'inheritFromElement'.
    return super.inheritFromElement(ancestor, aspect: aspect);
                 ^^^^^^^^^^^^^^^^^^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:259:19: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.

 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
        ? context.inheritFromWidgetOfExactType(type) as InheritedProvider<T>
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

../../../flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:260:19: Error: The method 'ancestorInheritedElementForWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'ancestorInheritedElementForWidgetOfExactType'.

        : context.ancestorInheritedElementForWidgetOfExactType(type)?.widget

FAILURE: Build failed with an exception.

* Where:
Script '/Users/eds/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 991

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/eds/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

VS Code 中的 iOS 构建错误

Command PhaseScriptExecution failed with a nonzero exit code

Xcode 中的 iOS 构建错误

...

    export variant\=normal
    /bin/sh -c /Users/eds/Downloads/rinoko/rinoko/build/ios/Runner.build/Debug-iphonesimulator/Runner.build/Script-9740EEB61CF901F6004384FC.sh

../../../flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/delegate_widget.dart:194:18: Error: Superclass has no method named 'inheritFromElement'.
    return super.inheritFromElement(ancestor, aspect: aspect);
                 ^^^^^^^^^^^^^^^^^^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:259:19: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
        ? context.inheritFromWidgetOfExactType(type) as InheritedProvider<T>
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:260:19: Error: The method 'ancestorInheritedElementForWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'ancestorInheritedElementForWidgetOfExactType'.
        : context.ancestorInheritedElementForWidgetOfExactType(type)?.widget
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Command PhaseScriptExecution failed with a nonzero exit code

我已经尝试过的

  • 更新所有组件(可能不是一个好主意?)
  • 扑通干净
  • 清理所有派生数据 (Xcode)
  • git reset --hard origin/master

一些想法

  • Big Sur 更新是否会更改任何读取和写入权限?
  • 再次删除并重新安装所有组件是否有意义?但实际上新的 Flutter 项目有效。

如果您需要更多堆栈跟踪等,也请告诉我。 我希望你有一些想法。 问候和感谢

1 个答案:

答案 0 :(得分:0)

就我而言,.env 文件丢失了。 在我包含该文件后,它就可以工作了。

其他解决方案可能是:

  • 删除 pubspec.lock 文件并运行 flutter pub get,然后运行应用。
  • 删除 C:\ 中的 .gradle 文件夹,然后构建应用程序。