我安装了Flutter并设置了Android Studio。然后我在GitHub (https://github.com/flutter/flutter)上克隆了一个flutter的例子,并在Android Studio中启动它,但它警告我“Dart SDK未配置”,这也发生在我的同事身上。但如果我在Android Studio中创建一个新项目,就完全没有问题。

我所做的:

安装了颤振 安装了Android Studio,以及Flutter插件,包括Dart插件 在命令行中颤振运行正常,所有五个测试都通过了。(见下文)

[✓] Flutter (on Mac OS X 10.13.3 17D47, locale en-US, channel dev) • Flutter version 0.0.22 at /Users/katelyn/flutter • Framework revision 3001b3307d (7 days ago), 2018-01-30 11:37:15 -0800 • Engine revision 8f2d72b183 • Tools Dart version 2.0.0-dev.16.0 • Engine Dart version 2.0.0-edge.7af4db0ea091dddca6b2da851e6dda8d7f9467e8 [✓] Android toolchain - develop for Android devices (Android SDK 27.0.3) • Android SDK at /Users/katelyn/Library/Android/sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-27, build-tools 27.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08) [✓] iOS toolchain - develop for iOS devices (Xcode 9.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 9.2, Build version 9C40b • ios-deploy 1.9.2 • CocoaPods version 1.4.0 [✓] Android Studio (version 3.0) • Android Studio at /Applications/Android Studio.app/Contents • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08) [✓] Connected devices • Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)

上周,我可以通过命令行运行他们的例子(在那个目录下),

flutter run 

但现在我显示一些错误与Gradle。

Launching lib/main.dart on Android SDK built for x86 in debug mode... Initializing gradle... 0.7s Resolving dependencies... Error running Gradle: Exit code 1 from: /Users/katelyn/AndroidStudioProjects/flutter/examples/flutter_gallery/android/gradlew app:properties: FAILURE: Build failed with an exception. Where: Build file '/Users/katelyn/AndroidStudioProjects/flutter/examples/flutter_gallery/android/app/build.gradle' line: 20 What went wrong: A problem occurred evaluating project ':app'. 3 Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Get more help at https://help.gradle.org BUILD FAILED in 0s Please review your Gradle project setup in the android/ folder.


当前回答

上面的大多数选项已经展示了如何在Windows系统中配置Dart(如果你已经安装了Dart, Flutter Doctor显示一切正常)。

在MacOS上,此选项可在Android Studio > Preferences ('Command' + ',')下使用

在左侧窗格中找到Languages and Frameworks / Dart。 勾选“启用Dart支持”并找到Dart SDK。它将在您的Flutter SDK安装目录'/ Flutter -安装-目录/ Flutter /bin/cache/dart-sdk'内。输入这个将自动填充下一行的dart版本,指出框架被选中。 选中框启用Dart支持以下模块为您所需的项目。

单击Apply。单击Ok。

如上所述,这将解决大多数用例。如果错误仍然存在,可以执行“File > Invalidate Caches/Restart”。

其他回答

我有同样的Dart SDK问题,我使用这个解决方案。为了解决这个问题,而不必每次都使用终端来测试我的程序,我遵循的步骤如下。

Find flutter SDK path. I did so by typing in echo $PATH and finding the path with /flutter/bin. Assuming your path is something like .../flutter/bin just add on /cache/dart-sdk/bin making it .../flutter/bin/cache/dart-sdk/bin. This .../flutter/bin/cache/dart-sdk/bin is the location of your Dart SDK. Assuming you say the same Dart SDK is not configured error accompanied by something where you can configure your Dart SDK. You click the configure option and set .../flutter/bin/cache/dart-sdk as your SDK. That should fix your problem. If not head over to the next step. Open your Android Studio preferences(Command + ',') and go to Languages and Frameworks>Dart. Under the Dart menu, you should be able to enter your Dart SDK path.

我使用IntelliJ IDEA完成了这些步骤,所以它们应该是差不多的。如果这不起作用,有时做一个虚拟的Dart项目可以让事情重新工作。这为我解决了一个类似的问题。

也许你可以在终端中执行'flutter pub get'来同步依赖项。

以防其他答案对你不起作用

如果你使用*nixOS或Mac

打开终端,输入颤振。你会得到/Users/mac/development/flutter/bin/flutter,在这个目录下,你会找到dart-sdk或(和)dart-sdk。旧的文件夹。复制它们的路径。 在mac上按ctrl+alt+s或cmd+打开首选项 语言和框架选择Dart找到Dart SDK路径。把那个 第一步复制到那里的路径。单击Apply。

如果这不能解决问题,你还必须设置Flutter SDK路径

在语言和框架下选择Flutter并找到Flutter SDK路径字段。 在文件夹层次结构中,您的flutter SDK路径相对于哪个flutter命令提供给您的路径高出两级。将其设置为在此头文件的第1步中找到的字段。再次单击“应用”并单击“保存”或“确定”。

在Mac

在尝试了一堆东西,和几次做一个新鲜的git克隆颤振项目..所有这些都无济于事,最后唯一有效的方法就是下载MacOS .zip文件,并以这种方式重新安装

https://flutter.dev/docs/get-started/install/macos

在我的情况下,Dart还单独安装了最新的Dart开发。所以当IntelliJ建议我配置dart时,我点击它,然后它指向C:/tools/dart。

所以,我必须去文件->设置->语言和框架->dart,并将SDK路径添加到我的Flutter SDK路径,使用dart SDK C:\ Flutter \bin\cache\dart- SDK。

请注意,正如其他人提到的,如果您指出了Flutter SDK路径,您可能不需要设置Dart SDK路径,因为Flutter SDK自带Dart SDK。