安装Flutter时Gradle运行失败

执行flutter run命令打包android项目时遇到了这个错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Jarvis-2:flutter_gallery jarvis$ flutter run
Launching lib/main.dart on SM G9600 in debug mode...
Initializing gradle... 1.1s
Resolving dependencies...
* Error running Gradle:
ProcessException: Process "/Users/admin/Documents/flutter/examples/flutter_gallery/android/gradlew" exited abnormally:

> Configure project :app
Checking the license for package Android SDK Platform 27 in /Users/admin/Library/Android/sdk/licenses
Warning: License for package Android SDK Platform 27 not accepted.


FAILURE: Build failed with an exception.

* Where:
Build file '/Users/admin/Documents/flutter/examples/flutter_gallery/android/build.gradle' line: 24

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
platforms;android-27 Android SDK Platform 27
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

Using Android SDK: /Users/admin/Library/Android/sdk

* 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 1s
Command: /Users/admin/Documents/flutter/examples/flutter_gallery/android/gradlew app:properties


Please review your Gradle project setup in the android/ folder.
Jarvis-2:flutter_gallery jarvis$ flutter doctor -v
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14 18A391, locale zh-Hans-CN)
• Flutter version 1.0.0 at /Users/admin/Documents/flutter
• Framework revision 5391447fae (8 weeks ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at /Users/admin/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.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-1136-b06)
• All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.0, Build version 10A255
• ios-deploy 1.9.4
• CocoaPods version 1.5.3

[✓] Android Studio (version 3.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 31.3.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[!] VS Code (version 1.30.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
• SM G9600 • 3949363555493098 • android-arm64 • Android 8.0.0 (API 26)
• iPhone • 756df34d9fd2baa79c128611bba8bf55a36d4360 • ios • iOS 9.3.2

! Doctor found issues in 1 category.

使用flutter doctor检测环境都是正常的

后来上flutter项目里提了个issue,发现是android SDK版本不对导致的,我调试的安卓设备是8.0版本,而新安装的Android Studio的SDK默认只有9.0版本

解决方案:
在Android Studio的设置里安装设备对应版本的SDK即可