Windows 下 搭建 Flutter 环境

阅读 3087
收藏 17
2018-06-28
原文链接:zdran.com

Flutter 环境搭建

本地环境

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

1. 通过 IDEA 下载 Android SDK

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

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

配置 AdnroidSDK的环境变量

1ANDROID_HOME=D:\AndroidSDK
2
3这里的 D:\AndroidSDK 要换成你自己的本地路径

2. 下载 Flutter SDK

配置环境变量:

1PUB_HOSTED_URL=https://pub.flutter-io.cn
2FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

使用git下载 flutter

1git clone -b beta https://github.com/flutter/flutter.git

配置 Flutter的环境变量,在path环境变量后面直接添加flutter的路径就可以

检查一下flutter安装情况,在命令行执行 flutter doctor

1flutter doctor
2
3Doctor summary (to see all details, run flutter doctor -v):
4[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
5[√] Android toolchain - develop for Android devices (Android SDK 28.0.0-rc2)
6[X] Android Studio (not installed)
7[√] IntelliJ IDEA Ultimate Edition (version 2017.2)
8[!] Connected devices
9    ! No devices available
10
11! Doctor found issues in 2 categories.
12
13
14出现上面的结果就说明成功了。
15

如果你出现了下面的这种结果:

1[✗] Android toolchain - develop for Android devices
2    ✗ Unable to locate Android SDK.
3      Install Android Studio from: https://developer.android.com/studio/index.html
4      On first launch it will assist you in installing the Android SDK components.
5      (or visit https://flutter.io/setup/#android-setup for detailed instructions).
6      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模拟器,但是,点击运行的时候一直提示

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

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

4. Gradle 的坑

能够显示模拟器了,点运行的时候会一直停在 Initializing gradle 的地方。

1Launching lib\main.dart on Android SDK built for x86 64 in debug mode...
2Initializing gradle...

检查一下 Gradle的环境变量。 如果没有就需要配置一下

1GRADLE_HOME=D:\tools\gradle-4.8.1
2追加 path 环境变量 ;%GRADLE_HOME%\bin

用管理员权限打开IDEA

如果还不行, 用IDEA的Terminal执行下面的命令

1cd android
2gradlew
3
4
5下面是运行时的结果:
6
7E:\workspace\hello_flutter>cd android
8E:\workspace\hello_flutter\android>gradlew
9
10> Configure project :app
11File C:\Users\unicom\.android\repositories.cfg could not be loaded.
12Checking the license for package Android SDK Platform 27 in D:\AndroidSDK\licenses
13License for package Android SDK Platform 27 accepted.
14Preparing "Install Android SDK Platform 27 (revision: 3)".
15"Install Android SDK Platform 27 (revision: 3)" ready.
16Installing Android SDK Platform 27 in D:\AndroidSDK\platforms\android-27
17"Install Android SDK Platform 27 (revision: 3)" complete.
18"Install Android SDK Platform 27 (revision: 3)" finished.
19
20> Task :help
21
22Welcome to Gradle 4.1.
23
24To run a build, run gradlew <task> ...
25
26To see a list of available tasks, run gradlew tasks
27
28To see a list of command-line options, run gradlew --help
29
30To see more detail about a task, run gradlew help --task <task>
31
32
33BUILD SUCCESSFUL in 1m 0s
341 actionable task: 1 executed
35E:\workspace\hello_flutter\android>flutter doctor
36Doctor summary (to see all details, run flutter doctor -v):
37[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
38[√] Android toolchain - develop for Android devices (Android SDK 28.0.0-rc2)
39[X] Android Studio (not installed)
40[√] IntelliJ IDEA Ultimate Edition (version 2017.2)
41[!] Connected devices
42    ! No devices available
43
44! Doctor found issues in 2 categories.
45

再次点击运行。我的成功的在模拟器上运行了。

如果,还是不能运行:追加CLASS_PATH 环境变量:;%GRADLE_HOME%\lib


PS:不得不吐糟一下flutter对Windows用户太不友好了。

学习一种新的技术,如果遇到问题 Github 上的 issues 区,是最好的去处!!

转载请注明出处
本文链接:zdran.com/20180625.ht…

评论