U2647's blog 一个热爱学习的 Java 程序员,喜欢 Vue,喜欢深度学习 Dubbo Flutter SpringBoot Debug Notes Java LeetCode Python Redis Android DesignPattern mdi-home-outline 首页 mdi-cloud-outline 标签云 mdi-timeline-text-outline 时间轴 mdi-draw-pen 文章总数 62
Windows 下 搭建 Flutter 环境 Windows 下 搭建 Flutter 环境 Windows Flutter IntelliJ IDEA Gradle Flutter SDK flutter doctor No connected devices found Unable to locate Android SDK mdi-cursor-default-click-outline 点击量 62

本地环境

  • Widnwos 7 64位
  • IntelliJ IDEA 2017.2.6
  • Java 1.8
  • Gradle 4.8.1
  • Git
  • Android SDK

1. 通过 IDEA 下载 Android SDK

File | Settings | Appearance Behavior | System Settings | Android SDK

记得要下载一个Android系统镜像

配置 AdnroidSDK的环境变量

ANDROID_HOME=D:\AndroidSDK

这里的 D:\AndroidSDK 要换成你自己的本地路径

2. 下载 Flutter SDK

配置环境变量:

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 的环境变量

3. 配置 IDEA

安装 Dart插件、 Flutter插件。安装后需要重启。

注意:最好使用管理员权限打开IDEA,否则后面会出现一系列的问题

创建一个 flutter项目。创建一个Android模拟器。

如果这个时候你很幸运的可以运行,那么就不用往下看了。

到这里之后,我明明创建了一个android模拟器,但是,点击运行的时候一直提示

No connected devices found; please connect a device, or see flutter.io/setup for getting started instructions.

使用管理员权限打开就没问题了!

4. Gradle 的坑

能够显示模拟器了,点运行的时候会一直停在 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 区,是最好的去处!!

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
我的GitHub 我的LeetCode 我的掘金
Powered by Hexo Powered by three-cards
Copyright © 2017 - {{ new Date().getFullYear() }} 某ICP备xxxxxxxx号