【问题标题】:How to solve "Execution failed for task ':app:compileFlutterBuildDebug'."如何解决“任务':app:compileFlutterBuildDebug'的执行失败。”
【发布时间】:2021-05-04 03:52:36
【问题描述】:

当我尝试在终端中使用“flutter run”在 android 上运行应用程序时,出现以下错误...

/C:/Users/Acer/AppData/Roaming/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);
                 ^^^^^^^^^^^^^^^^^^
/C:/Users/Acer/AppData/Roaming/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' ('/D:/Flutter/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>
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/Users/Acer/AppData/Roaming/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' ('/D:/Flutter/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
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/Users/Acer/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/flutter_svg-0.18.1/lib/src/picture_provider.dart:50:59: Error: No named parameter with 
the name 'nullOk'.
        context != null ? Localizations.localeOf(context, nullOk: true) : null,
                                                          ^^^^^^
/D:/Flutter/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't match.
  static Locale localeOf(BuildContext context) {
                ^^^^^^^^
                                                                        

FAILURE: Build failed with an exception.

* Where:
Script 'D:\Flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\Flutter\flutter\bin\flutter.bat'' 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

BUILD FAILED in 1m 50s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                       121.0s
Exception: Gradle task assembleDebug failed with exit code 1

问题是昨天它工作正常,但今天它显示此错误消息。 请帮忙解决。

【问题讨论】:

  • 检查你的颤振频道。我把我的换成稳定的,它起作用了。另外,升级到最新的颤振版本。
  • 我遇到了类似的问题。降级颤振解决了这个问题。
  • 请接受解决您问题的答案。它也会帮助其他正在寻找解决方案的人。

标签: flutter visual-studio-code


【解决方案1】:

您可能在“稳定”以外的频道中升级了颤振。 在这种情况下,最简单的解决方案是简单地打开一个终端并运行(输入) flutter downgrade.

【讨论】:

    【解决方案2】:

    编辑 - 使用颤振 2 后,它将无法工作。答案现在已经过时了

    切换到主频道时遇到此问题。不得不降级

    flutter channel stable && flutter upgrade
    

    修复了问题

    【讨论】:

      【解决方案3】:

      更新提供者版本 4.3.3 它将解决问题

      【讨论】:

      • @PinkeshDarji 很棒
      【解决方案4】:

      请将您的依赖项升级到最新版本。我自己找到解决方案。这个错误是由于复制了旧版本上的完整代码而发生的,现在最新版本启用了空安全,所以这就是问题的原因。

      【讨论】:

        【解决方案5】:

        过去 3 天我遇到了同样的问题。 如果您不想使用降级的颤振版本,我还有一个解决方案: 首先,更新你的颤振版本,以防你使用以下方法降级:

        flutter upgrade
        

        在您的终端中。

        您可以在调试控制台中注意到您正在使用提供程序

        版本 3.2.0

        来自错误输出。我想如果你使用的提供者版本大于

        版本 4.0.0

        只需将provider: ^3.2.0 替换为provider: ^4.0.0

        (您可以在 pubspec.yaml 文件中进行调整)

        然后它会起作用。

        试一试,如果能解决问题,请告诉我:)

        【讨论】:

          猜你喜欢
          • 2021-12-08
          • 2020-09-07
          • 1970-01-01
          • 1970-01-01
          • 2022-07-04
          • 2021-09-25
          • 2021-08-21
          • 1970-01-01
          • 2022-07-04
          相关资源
          最近更新 更多