File | Settings | Appearance Behavior | System Settings | Android SDK
记得要下载一个Android系统镜像
配置 AdnroidSDK的环境变量
ANDROID_HOME=D:\AndroidSDK
这里的 D:\AndroidSDK 要换成你自己的本地路径
配置环境变量:
PUB_HOSTED_URL=https://pub.flutter-io.cn
FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
使用git下载 flutter
git clone -b beta https://github.com/flutter/flutter.git
配置 Flutter的环境变量,在path环境变量后面直接添加flutter的路径就可以
检查一下flutter安装情况,在命令行执行 flutter doctor
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.0-rc2)
[X] Android Studio (not installed)
[√] IntelliJ IDEA Ultimate Edition (version 2017.2)
[!] Connected devices
! No devices available
! Doctor found issues in 2 categories.
出现上面的结果就说明成功了。
如果你出现了下面的这种结果:
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.io/setup/#android-setup for detailed instructions).
If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location.
应该是本地没有Android SDK,或者没有配置 $ANDROID_HOME
的环境变量
安装 Dart插件、 Flutter插件。安装后需要重启。
注意:最好使用管理员权限打开IDEA,否则后面会出现一系列的问题
创建一个 flutter项目。创建一个Android模拟器。
如果这个时候你很幸运的可以运行,那么就不用往下看了。
到这里之后,我明明创建了一个android模拟器,但是,点击运行的时候一直提示
No connected devices found; please connect a device, or see flutter.io/setup for getting started instructions.
使用管理员权限打开就没问题了!
能够显示模拟器了,点运行的时候会一直停在 Initializing gradle 的地方。
Launching lib\main.dart on Android SDK built for x86 64 in debug mode...
Initializing gradle...
检查一下 Gradle的环境变量。 如果没有就需要配置一下
GRADLE_HOME=D:\tools\gradle-4.8.1
追加 path 环境变量 ;%GRADLE_HOME%\bin
用管理员权限打开IDEA
如果还不行, 用IDEA的Terminal执行下面的命令
cd android
gradlew
下面是运行时的结果:
E:\workspace\hello_flutter>cd android
E:\workspace\hello_flutter\android>gradlew
> Configure project :app
File C:\Users\unicom\.android\repositories.cfg could not be loaded.
Checking the license for package Android SDK Platform 27 in D:\AndroidSDK\licenses
License for package Android SDK Platform 27 accepted.
Preparing "Install Android SDK Platform 27 (revision: 3)".
"Install Android SDK Platform 27 (revision: 3)" ready.
Installing Android SDK Platform 27 in D:\AndroidSDK\platforms\android-27
"Install Android SDK Platform 27 (revision: 3)" complete.
"Install Android SDK Platform 27 (revision: 3)" finished.
> Task :help
Welcome to Gradle 4.1.
To run a build, run gradlew <task> ...
To see a list of available tasks, run gradlew tasks
To see a list of command-line options, run gradlew --help
To see more detail about a task, run gradlew help --task <task>
BUILD SUCCESSFUL in 1m 0s
1 actionable task: 1 executed
E:\workspace\hello_flutter\android>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.0-rc2)
[X] Android Studio (not installed)
[√] IntelliJ IDEA Ultimate Edition (version 2017.2)
[!] Connected devices
! No devices available
! Doctor found issues in 2 categories.
再次点击运行。我的成功的在模拟器上运行了。
如果,还是不能运行:追加CLASS_PATH 环境变量:;%GRADLE_HOME%\lib
PS:不得不吐糟一下flutter对Windows用户太不友好了。
学习一种新的技术,如果遇到问题 Github 上的 issues 区,是最好的去处!!