如何解决:任务':app:compileFlutterBuildDebug'执行失败

Posted

技术标签:

【中文标题】如何解决:任务\':app:compileFlutterBuildDebug\'执行失败【英文标题】:how to solve: Execution failed for task ':app:compileFlutterBuildDebug'如何解决:任务':app:compileFlutterBuildDebug'执行失败 【发布时间】:2021-12-08 03:43:54 【问题描述】:

运行flutter后出现此错误,我已经切换到master频道并降级了flutter,也切换到了stable频道并降级了。我还删除了 pubspec.lock 然后运行 ​​pub get 仍然出现此错误。

这是整个错误信息:

Launching lib/main.dart on android SDK built for x86 in debug mode...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
../../../sdks/flutter/.pub-cache/hosted/pub.dartlang.org/states_rebuilder-1.3.2/lib/src/bloc_provider.dart:22:17: Error: The method 'ancestorInheritedElementForWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../sdks/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 '/home/enel/sdks/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1035

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/enel/sdks/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

BUILD FAILED in 1m 8s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

【问题讨论】:

【参考方案1】:

尝试以下方法:

转到pubspec.yaml 文件,尝试执行Packages get | Pub get,然后再次构建项目。

或者试试这个:

flutter clean and flutter pub get

在终端,问题解决了!

希望能解决!

【讨论】:

我已经完成了,我仍然得到同样的错误

以上是关于如何解决:任务':app:compileFlutterBuildDebug'执行失败的主要内容,如果未能解决你的问题,请参考以下文章

如何解决任务':app:compileFlutterBuildDebug'的执行失败

如何解决Android中的“任务':app:processDebugResources'执行失败”?

如何解决应用程序 processDebugResources 错误?

我如何在颤振应用程序中解决这个问题

苹果手机试玩app如何无限做任务技术教程!

任务“:app:packageReleaseBundle”执行失败