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


当前回答

mac:

点击顶部的Android Studio ->点击首选项->语言和框架

->选择“颤振”

->浏览Flutter SDK路径下载链接["https://flutter.dev/docs/get-started/install/macos"]

->单击“确定” 享受! !

其他回答

在我的情况下,它是更新颤振sdk路径在android工作室,偏好。

mac:

点击顶部的Android Studio ->点击首选项->语言和框架

->选择“颤振”

->浏览Flutter SDK路径下载链接["https://flutter.dev/docs/get-started/install/macos"]

->单击“确定” 享受! !

执行如下命令:

$ echo "$(dirname $(which flutter))/cache/dart-sdk"

你会得到这样的东西:

/home/lex/opt/flutter/bin/cache/dart-sdk

输入该值作为Dart SDK路径。

这通常发生在在其他机器上创建的项目上。要在Android Studio 3.1.3上修复此问题:

文件->设置(ctrl+alt+s) 语言和框架-> Dart 勾选“为项目启用Dart支持…” 在“Dart SDK路径”中单击“…”并导航到flutter SDK目录。在这个目录下你会找到“bin/cache/dart-sdk”。这是你应该使用的dart sdk路径。 点击“应用” 关闭项目并再次打开它(有时需要这一步,有时不需要)

编辑2019-05-28 -我不知道这个选项启用了多长时间,但我注意到在Android Studio 3.4中,在其他机器上开发的项目中启用Dart支持更容易。

用Gradle文件同步项目 构建完成后,单击编辑器面板顶部的“启用dart支持”。

我按照以下步骤来解决这个问题:

首先,转到:文件->设置->语言和框架->颤振

在“flutter SDK path”下面,输入您安装flutter的位置 我的是:C:\src\flutter

点击应用,然后确定,android工作室将刷新。 问题会解决的。