MAC 電腦 Flutter 開發環境的安裝搭建



layout: post
title: "MAC 電腦 Flutter 開發環境的安裝搭建"
date: 2019-04-16
author: "袁鳳鳴"
excerpt: MAC 電腦 Flutter 開發環境的安裝搭建

categories:
- flutter
tags:
- flutter
mathjax: true


原文在我博客網站:https://www.yfmingo.cn/2019/04/16/flutter-environment-install/

0x01-1、2-1 Flutter開發環境的安裝-01:

image

0x01-2、2-1 Flutter開發環境的安裝-02:

image

0x02、JDK 安裝:

由於官網下載比較緩慢。可以下載我百度網盤的JDK:鏈接: https://pan.baidu.com/s/1ibnt4PnJgOwFjxNdI3l47Q 提取碼: v2jj 復制這段內容后打開百度網盤手機App,操作更方便哦;
image

Mac下如何安裝JDK:詳細過程可以參考:https://www.cnblogs.com/quickcodes/p/5127101.html
安裝好JDK后需要配置JDK的環境變量:請參考:Mac下如何配置環境變量

0x03、Flutter JDK 安裝:

由於官網下載比較緩慢。可以下載我百度網盤的Flutter SDKhttps://pan.baidu.com/s/1OQLCy44KBbd1IoBuUzz1eQ
image


我的 `Flutter` 安裝在了如下路徑(`home`目錄下載新建一個`app`文件夾中)

image

  • 配置環境變量:

  • 在終端執行 opne ~/.bash_profile ,加入 Flutter 的安裝路徑

    • export PATH=/Users/mingo/app/flutter/bin:$PATH
      image

    • 保存關閉 執行:source ~/.bash_profile

  • 這個時候應該能運行flutter命令了,我們運行命令行:flutter -h

    • 出現如下:
$ flutter -h
Manage your Flutter app development.

Common commands:

  flutter create <output directory>
    Create a new Flutter project in the specified directory.

  flutter run [options]
    Run your Flutter application on an attached device or in an emulator.

Usage: flutter <command> [arguments]

Global options:
-h, --help                  Print this usage information.
-v, --verbose               Noisy logging, including all shell commands executed.
                            If used with --help, shows hidden options.

-d, --device-id             Target device id or name (prefixes allowed).
    --version               Reports the version of this tool.
    --suppress-analytics    Suppress analytics reporting when this command runs.
    --bug-report            Captures a bug report file to submit to the Flutter team.
                            Contains local paths, device identifiers, and log snippets.

    --packages              Path to your ".packages" file.
                            (required, since the current directory does not contain a ".packages" file)

Available commands:
  analyze                  Analyze the project's Dart code.
  attach                   Attach to a running application.
  bash-completion          Output command line shell completion setup scripts.
  build                    Flutter build commands.
  channel                  List or switch flutter channels.
  clean                    Delete the build/ and .dart_tool/ directories.
  config                   Configure Flutter settings.
  create                   Create a new Flutter project.
  devices                  List all connected devices.
  doctor                   Show information about the installed tooling.
  drive                    Runs Flutter Driver tests for the current project.
  emulators                List, launch and create emulators.
  format                   Format one or more dart files.
  help                     Display help information for flutter.
  install                  Install a Flutter app on an attached device.
  logs                     Show log output for running Flutter apps.
  make-host-app-editable   Moves host apps from generated directories to non-generated directories so that they can be
                           edited by developers.
  packages                 Commands for managing Flutter packages.
  precache                 Populates the Flutter tool's cache of binary artifacts.
  run                      Run your Flutter app on an attached device.
  screenshot               Take a screenshot from a connected device.
  stop                     Stop your Flutter app on an attached device.
  test                     Run Flutter unit tests for the current project.
  trace                    Start and stop tracing for a running Flutter app.
  upgrade                  Upgrade your copy of Flutter.
  version                  List or switch flutter versions.

Run "flutter help <command>" for more information about a command.
Run "flutter help -v" for verbose help output, including less commonly used options.

  ╔════════════════════════════════════════════════════════════════════════════╗
  ║                 Welcome to Flutter! - https://flutter.io                   ║
  ║                                                                            ║
  ║ The Flutter tool anonymously reports feature usage statistics and crash    ║
  ║ reports to Google in order to help Google contribute improvements to       ║
  ║ Flutter over time.                                                         ║
  ║                                                                            ║
  ║ Read about data we send with crash reports:                                ║
  ║ https://github.com/flutter/flutter/wiki/Flutter-CLI-crash-reporting        ║
  ║                                                                            ║
  ║ See Google's privacy policy:                                               ║
  ║ https://www.google.com/intl/en/policies/privacy/                           ║
  ║                                                                            ║
  ║ Use "flutter config --no-analytics" to disable analytics and crash         ║
  ║ reporting.                                                                 ║
  ╚════════════════════════════════════════════════════════════════════════════╝

0x04、Flutter 檢查環境:

0x04-1、Flutter 提供了 檢查環境 命令 flutter doctor
# mingo @ 192 in ~ [12:59:45] 
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.13.6 17G4015, locale zh-Hans-CN)
[✗] 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.
      You may also want to add it to your PATH environment variable.

[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
        brew update
        brew install --HEAD usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
[!] Android Studio (not installed)
[!] IntelliJ IDEA Ultimate Edition (version 2018.3.5)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
    ! No devices available

! Doctor found issues in 5 categories.

# mingo @ 192 in ~ [13:03:33] 

如上:帶❌的就必須按照。帶❗️的就可以暫時忽略。

0x04-2、安裝 Android Studio 和 VS Code

打開android studio, 打開plugins ,安裝flutter
image

輸入flutter搜索,點擊中間的 Search in repositories

image

點擊install,順利的話安裝完畢之后重啟android studio

再次運行

然后在 flutter doctor

# mingo @ 192 in ~ [13:03:33] 
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.13.6 17G4015, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    ✗ Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
        brew update
        brew install --HEAD usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
[✓] Android Studio (version 3.3)
[!] IntelliJ IDEA Ultimate Edition (version 2018.3.5)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
    ! No devices available

! Doctor found issues in 4 categories.
0x04-3、執行flutter doctor --android-licenses同意相關協議
# mingo @ 192 in ~ [13:22:07] 
$ flutter doctor --android-licenses
.
.
.此處 N 多信息,都是相關協議文件,一路 y 即可。
.
.
---------------------------------------
Accept? (y/N): y
All SDK package licenses accepted


# mingo @ 192 in ~ [13:22:48] 
$ flutter doctor                   
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.13.6 17G4015, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
        brew update
        brew install --HEAD usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
[✓] Android Studio (version 3.3)
[!] IntelliJ IDEA Ultimate Edition (version 2018.3.5)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
    ! No devices available

! Doctor found issues in 3 categories.

# mingo @ 192 in ~ [1:02:09] 

0x04-4、解決 iOS 環境

按照如下截圖,依次一個個執行如圖命令。
image

第六個命令 brew install ios-deploy 安裝完如下:

# mingo @ 192 in ~ [13:49:02] 
$ brew install ios-deploy
==> Downloading https://homebrew.bintray.com/bottles/ios-deploy-1.9.4.high_sierra.bottle.tar
######################################################################## 100.0%
==> Pouring ios-deploy-1.9.4.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/ios-deploy/1.9.4: 7 files, 157.2KB

# mingo @ 192 in ~ [13:58:36] 

在 檢查環境

# mingo @ 192 in ~ [0:35:18] 
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.13.6 17G4015, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
[✓] Android Studio (version 3.3)
[!] IntelliJ IDEA Ultimate Edition (version 2018.3.5)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.33.1)
[✓] Connected device (2 available)

! Doctor found issues in 1 category.

# mingo @ 192 in ~ [0:36:26] 

因為不需要使用 IntelliJ IDEA來開發,如果你電腦中沒有安裝IntelliJ IDEA是不會提示這個警告的,所以可以先不管這個欄目的❗️和 ❌
image

到此,Flutter 環境搭建完成,可以用 Android Studio,新建第一個 Flutter項目了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM