Flutter:FAILURE:构建失败,出现异常无法创建任务':app:compileFlutterBuildDebug'。必须提供 Flutter 源码目录

Posted

技术标签:

【中文标题】Flutter:FAILURE:构建失败,出现异常无法创建任务\':app:compileFlutterBuildDebug\'。必须提供 Flutter 源码目录【英文标题】:Flutter: FAILURE: Build failed with an exception on Could not create task ':app:compileFlutterBuildDebug'. Must provide Flutter source directoryFlutter:FAILURE:构建失败,出现异常无法创建任务':app:compileFlutterBuildDebug'。必须提供 Flutter 源码目录 【发布时间】:2021-11-09 19:56:23 【问题描述】:

最近我将我的项目迁移到一个新系统并纠正了所有错误,但我遇到了一个异常,说提供颤振源目录。 我添加了颤振SDK路径并检查但我仍然无法解决 问题。

FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutterSDK\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 572

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > Could not create task ':app:compileFlutterBuildDebug'.
      > Must provide Flutter source directory

* 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.

我已经运行了 Flutter Doctor cmd,一切都很好

flutter doctor -v
[√] Flutter (Channel stable, 2.5.0, on Microsoft Windows [Version 10.0.19043.1165], locale en-IN)
    • Flutter version 2.5.0 at C:\src\flutterSDK\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4cc385b4b8 (6 days ago), 2021-09-07 23:01:49 -0700
    • Engine revision f0826da7ef
    • Dart version 2.14.0

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\Barfi Nandeti\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 2020.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] VS Code (version 1.60.0)
    • VS Code at C:\Users\Barfi Nandeti\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (2 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 93.0.4577.63
    • Edge (web)   • edge   • web-javascript • Microsoft Edge 93.0.961.47

• No issues found!

【问题讨论】:

【参考方案1】:

这可能是因为 Flutter SDK 与您的旧机器位于不同的目录中。 Checkout this answer.

【讨论】:

以上是关于Flutter:FAILURE:构建失败,出现异常无法创建任务':app:compileFlutterBuildDebug'。必须提供 Flutter 源码目录的主要内容,如果未能解决你的问题,请参考以下文章

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

FAILURE:通过“flutter build appbundle”命令构建项目时构建失败并出现异常

Flutter - FAILURE:构建失败并出现异常。 - 无法启动守护进程。 - 安卓工作室 - VSCode

FAILURE:构建失败并出现异常。 * 其中:构建文件 'D:\AProjects\flutter_app\android\app\build.gradle' 行:24

错误:找不到类型“表元数据”| FAILURE:构建失败并出现异常

Flutter:构建失败并出现异常