我安装了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.


当前回答

如果你在现有项目中选择dart-sdk路径后仍然得到警告信号——

——关闭Android Studio

只要删除。dart_tool文件夹(通常是你的文件夹的第一个文件夹) 项目)

——现在打开Android Studio并尝试像所展示的技术一样设置路径 以上——

 File -> Settings -> Languages and Frameworks -> Dart

现在启用复选框并设置dart-sdk路径,现在它不会显示 警告。

您的项目将成功同步。

谢谢你!

其他回答

我使用的是Win10 Pro;

如果你正在使用Android Studio,并得到这个消息“错误:Dart SDK未在指定位置找到”,

我的解决办法是这样的。

点击文件/设置或Ctrl+Alt+S打开设置窗口。 转到“语言和框架”,点击Dart 选中“YOUR_PROJECT_NAME”项目启用Dart支持 对于Path Dart SDK路径:输入存储颤振目录的位置。 向下钻取该目录,直到看到Dart SDK目录C:\flutter\bin\cache\ Dart - SDK。您还可以检查SDK更新,通过勾选复选框,然后单击“立即检查”来获得最新版本。

这对我很管用。

我有同样的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项目可以让事情重新工作。这为我解决了一个类似的问题。

我解决了,试试:

点击打开SDK设置,打开Flutter,然后在下载时添加SDK位置。

在我的机器里安装了颤振

C:\src\flutter

我设置dart sdk路径为

C:\src\flutter\bin\cache\dart-sdk

这解决了我的问题

事实上,在运行应用程序之前检查设置是一个好习惯。

你检查过java SDK路径吗?(事实上,如果你已经运行了另一个应用程序,但未能运行这个,这可能是从Github或其他人下载的。 然后你可能需要检查颤振设置和省道设置。