每接触一个新的技术,总要踩很多坑,特别是在OS 上 (对于一个不熟悉OS的),这里按照官方的 环境搭建方法按部就班的来:

下载Flutter SDK包

这里推荐去官网:https://flutterchina.club/get-started/install/

在按照官方文档安装好flutter后

配置环境变量

压缩包下载好以后,找个位置进行解压。这个位置很重要,因为下面配置环境变量的时候要用到。比如你配置到了根目录下的app文件夹。

1.打开终端工具,使用vim进行配置环境变量,命令如下:

vim ~/.bash_profile  

2.在文件的末未添加一下代码。

export PATH=’/Users/你机器的名字/Flutter/flutter/bin’:$PATH

PS:查看flutter的位置

which flutter

 /Users/你机器的名字/Flutter/flutter/bin

提示:这行命令你要根据你把压缩包解压的位置来进行编写,写的是你的路径,很有可能不跟文章一样。

完成这部以后,就算我们flutter的安装工作完成了,但是这还不能进行开发。可以使用命令来检测一下,是否安装完成了。

flutter -h

配置完成后,需要用 source 命令重新加载一下 ,具体命令如下:

source ~/.bash_profile

如果出现以下文字说明安装成功:

Manage your Flutter app development.

Common commands:

  flutter create

    Create a new Flutter project in the specified directory.

  flutter run [options]

    Run your Flutter application on an attached device or in an emulator.

检查开发环境

到上边为止,我们安装好了Flutter,但是还不具备开发环境。开发还需要很多软件和插件的支持,我们可以使用Flutter为我们提供的命令来进行检查:

flutter doctor

frc 38b11bfb7225d0d238e9b628bc1a0aea - flutter构建之旅 1安装flutter

我们可以看到有许多画小差的条目,所以就需要我们安装检测结果一条条进行安装,直到满足开发环境。

Android Studio下载地址: www.android-studio.org/

接下在在终端里输入下列命令,每输完一个都要等一会,等待软件包安装完成:

brew install –HEAD libimobiledevice

brew install ideviceinstaller

brew install ios-deploy

brew install cocoapods

pod setup

最后的两个问题是出现在Android studio里面的:

✗ Flutter plugin not installed;this adds Flutter specific functionality.

✗ Dart plugin not installed;this adds Dart specific functionality.

解决办法:

打开Android studio -> preference -> plugin  -> search flutter,安装Dart和Flutter

frc 9a4bbaf3fcf08a1cdcb40671f199287c - flutter构建之旅 1安装flutter

最后如果安装成功,执行flutter doctor,会出现下面内容:

Doctor summary (to see all details, run flutter doctor -v):

[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.4 18E226, locale

    zh-Hans-CN)

[✓] Android toolchain – develop for Android devices (Android SDK version 28.0.3)

[!] iOS toolchain – develop for iOS devices (Xcode 10.2)

    ! CocoaPods out of date (1.5.0 is recommended).

        CocoaPods is used to retrieve the iOS platform side’s plugin code that

        responds to your plugin usage on the Dart side.

        Without resolving iOS dependencies with CocoaPods, plugins will not work

        on iOS.

        For more info, see https://flutter.io/platform-plugins

      To upgrade:

        brew upgrade cocoapods

        pod setup

[✓] Android Studio (version 3.3)

[✓] Connected device (1 available)

! Doctor found issues in 1 category.

flutter构建之旅 1安装flutter