安装Flutter其实就五个步骤:下载安装包 - 设置Path环境变量 - 执行flutter doctor - 配置Xcode - 下载VS Code并配置
一、下载安装包
- 下载Flutter SDK
下载SDK有两种方式
方法1: 点击 SDK -> Stable channel (macOS) -> v1.5.4-hotfix.2
方法2: 打开Terminal -> cd 指定目录中 -> 执行 git clone -b stable https://github.com/flutter/flutter.git 命令
cd /Users/ws/Library/Flutter
git clone -b stable https://github.com/flutter/flutter.git
下载最新版 Xcode
Appstore -> Xcode解压并安装
如果使用方法1,解压到指定目录可以用以下方法
cd /Users/ws/Library/Flutter
unzip ~/Downloads/flutter_macos_v0.5.1-beta.zip
也可以直接解压然后放入指定目录中
小结:如果使用方法1下载下来的安装包执行flutter doctor时报下面Error中的错误,可以删除安装包,然后使用方法2中重新下载。(这是后面步骤操作,我提前说下,当前步骤不用这个)
二、 设置Path变量环境
- 打开终端Terminal,然后输入
vi ~/.bash_profile
- 然后 输入 i 进入可编辑状态,然后再加入如下代码到 文件中 然后 Esc : wq 保存
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin:$PATH
a. 确定您Flutter SDK的目录,您将在步骤3中用到。
b. 打开(或创建) $HOME/.bash_profile. 文件路径和文件名可能在您的机器上不同.
c. 添加以下行并更改[PATH_TO_FLUTTER_GIT_DIRECTORY]为克隆Flutter的git repo的路径;
比如我的为 /Users/ws/Library/Flutter则替换为
export PATH=/Users/ws/Library/Flutter/flutter/bin:$PATH
然后执行此命令,生效当前文件
source ~/.bash_profile
- 如果你是用的是zsh,终端启动时 ~/.bash_profile 将不会被加载,解决办法就是修改 ~/.zshrc ,在其中添加:source ~/.bash_profile
vi ~/.zshrc
然后添加
source ~/.bash_profile
然后保存运行生效
source ~/.zshrc
- 通过运行flutter/bin命令验证目录是否在已经在PATH中:
echo $PATH
结果为三、执行flutter doctor
执行 以下命令
flutter doctor
查看是否需要安装其它依赖项来完成安装
- Error 报错
在执行 flutter doctor 命令后,报如下错误
Error: The Flutter directory is not a clone of the GitHub project.
The flutter tool requires Git in order to operate properly;
to set up Flutter, run the following command:
git clone -b stable https://github.com/flutter/flutter.git
那么就删除刚才的安装包,然后cd 到你需要安装flutter文件夹的文件中,然后执行以下代码,重新下载
git clone -b stable https://github.com/flutter/flutter.git
漫长的等待...
然后再执行 flutter doctor
wsdeMacBook-Pro:Flutter ws$ flutter doctor
Downloading Dart SDK from Flutter engine 2994f7e1e682039464cb25e31a78b86a3c59b695...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 200M 100 200M 0 0 435k 0 0:07:51 0:07:51 --:--:-- 288k
Building flutter tool...
╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.dev ║
║ ║
║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
║ statistics and basic crash reports. This data is used to help improve ║
║ Flutter tools over time. ║
║ ║
║ Flutter tool analytics are not sent on the very first run. To disable ║
║ reporting, type 'flutter config --no-analytics'. To display the current ║
║ setting, type 'flutter config'. If you opt out of analytics, an opt-out ║
║ event will be sent, and then no further information will be sent by the ║
║ Flutter tool. ║
║ ║
║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║
║ Note: The Google Privacy Policy describes how data is handled in this ║
║ service. ║
║ ║
║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║
║ crash reports to Google. ║
║ ║
║ 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/ ║
╚════════════════════════════════════════════════════════════════════════════╝
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this
source!
Downloading Material fonts... 1.7s
Downloading Gradle Wrapper... 0.1s
Downloading android-arm-profile/darwin-x64 tools... 2.3s
Downloading android-arm-release/darwin-x64 tools... 3.3s
Downloading android-arm64-profile/darwin-x64 tools... 5.6s
Downloading android-arm64-release/darwin-x64 tools... 4.2s
Downloading android-x64-profile/darwin-x64 tools... 7.8s
Downloading android-x64-release/darwin-x64 tools... 2.6s
Downloading package sky_engine... 1.0s
Downloading common tools... 19.0s
Downloading common tools... 8.7s
Downloading darwin-x64 tools... 48.2s
Downloading libimobiledevice... 0.3s
Downloading usbmuxd... 0.2s
Downloading libplist... 0.2s
Downloading openssl... 1.6s
Downloading ideviceinstaller... 0.1s
Downloading ios-deploy... 0.2s
Downloading libzip... 0.1s
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.14.6 18G103, 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.dev/setup/#android-setup for detailed instructions).
If the 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.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
[!] Android Studio (not installed)
[!] Connected device
! No devices available
! Doctor found issues in 3 categories.
- 然后再执行 以下命令查看配置
flutter doctor -v
执行结果
wushuangdeMacBook-Pro:Flutter wushuang$ flutter doctor -v
[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.14.6 18G103,
locale zh-Hans-CN)
• Flutter version 1.12.13+hotfix.5 at
/Users/wushuang/Library/Flutter/flutter
• Framework revision 27321ebbad (4 weeks ago), 2019-12-10 18:15:01 -0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0
[✗] 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.dev/setup/#android-setup for detailed
instructions).
If the 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.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3, Build version 11C29
• CocoaPods version 1.8.3
[!] Android Studio (not installed)
• Android Studio not found; download from
https://developer.android.com/studio/index.html
(or visit https://flutter.dev/setup/#android-setup for detailed
instructions).
[✓] Connected device (1 available)
• iPhone 11 Pro Max • 5477F382-441E-4FA4-AE1F-D8EB63B5AA3E • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)
! Doctor found issues in 2 categories.
发现其中有“Android toolchain - develop for Android devices”前面有个红色 [x],其实只要保证Xcode 和 Android toolchain 有一个成功就行,当然也可以再下载补全
四、配置Xcode
- 安装 homebrew(如果已经安装homebrew就跳过)
可以点击homebrew 进去官网查看下载链接,也可以在Terminal 中执行
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 打开Terminal 然后逐条运行这些命令来安装用于将Flutter应用安装到iOS设备的工具
brew update
brew install --HEAD libimobiledevice
brew install ideviceinstaller ios-deploy cocoapods
pod setup
又是经过漫长的下载... 😂
最后结果
wushuangdeMacBook-Pro:~ wushuang$ brew update
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3.mavericks.bottle.tar.gz
########################### 38.8%^C
wushuangdeMacBook-Pro:~ wushuang$ brew update
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': transfer closed with outstanding read data remaining
Error: Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring portable-ruby-2.6.3.mavericks.bottle.tar.gz
wushuangdeMacBook-Pro:~ wushuang$ brew install --HEAD libimobiledevice
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
imagemagick imagemagick@6 pyenv
==> Installing dependencies for libimobiledevice: gdbm, sqlite, xz, python, libxml2, libplist, libtasn1, libusb and libusbmuxd
==> Installing libimobiledevice dependency: gdbm
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.18.1.mojave.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring gdbm-1.18.1.mojave.bottle.1.tar.gz
🍺 /usr/local/Cellar/gdbm/1.18.1: 20 files, 586.8KB
==> Installing libimobiledevice dependency: sqlite
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.30.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/5e/5e6fef2d754e0e4009d502c40ad1846ac46937886b5f3fe89378cb838626d95e?__gda__=exp=1578319393~hmac=290bf0800a72de504fa502a68d003374ed1ba33913b
######################################################################## 100.0%
==> Pouring sqlite-3.30.1.mojave.bottle.tar.gz
==> Caveats
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.
If you need to have sqlite first in your PATH run:
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile
For compilers to find sqlite you may need to set:
export LDFLAGS="-L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/sqlite/include"
For pkg-config to find sqlite you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/sqlite/3.30.1: 11 files, 3.9MB
==> Installing libimobiledevice dependency: xz
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.4.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/01/010667293df282c8bceede3bcd36953dd57c56cef608d09a5b50694ab7d4b96b?__gda__=exp=1578319520~hmac=121c30a68227ba090f2c57d4f2b087be4a7ee84ad72
######################################################################## 100.0%
==> Pouring xz-5.2.4.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/xz/5.2.4: 92 files, 1MB
==> Installing libimobiledevice dependency: python
==> Downloading https://homebrew.bintray.com/bottles/python-3.7.6_1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/64/643d627c2b4fc03a3286c397d299284ef8ce2d4a832737e41175f297d4f0862e?__gda__=exp=1578319534~hmac=362369ee5a44602b7266c4c136355eb5cd0e93d0105
######################################################################## 100.0%
==> Pouring python-3.7.6_1.mojave.bottle.tar.gz
==> /usr/local/Cellar/python/3.7.6_1/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python/3.7.6_1/bin --install-lib=/usr/local/lib/py
==> /usr/local/Cellar/python/3.7.6_1/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python/3.7.6_1/bin --install-lib=/usr/local/lib/py
==> /usr/local/Cellar/python/3.7.6_1/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python/3.7.6_1/bin --install-lib=/usr/local/lib/py
==> Caveats
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
If you need Homebrew's Python 2.7 run
brew install python@2
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
🍺 /usr/local/Cellar/python/3.7.6_1: 3,977 files, 60.8MB
==> Installing libimobiledevice dependency: libxml2
==> Downloading https://homebrew.bintray.com/bottles/libxml2-2.9.10.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/47/472ed1a73a91c49fd9f39bd8cc4a7472b09c691659b3b9305c9da42ed35e1475?__gda__=exp=1578319613~hmac=eb1560ca42d4386c9a6b50d8389276eda31531de67e
######################################################################## 100.0%
==> Pouring libxml2-2.9.10.mojave.bottle.tar.gz
==> Caveats
libxml2 is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have libxml2 first in your PATH run:
echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.bash_profile
For compilers to find libxml2 you may need to set:
export LDFLAGS="-L/usr/local/opt/libxml2/lib"
export CPPFLAGS="-I/usr/local/opt/libxml2/include"
For pkg-config to find libxml2 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/libxml2/2.9.10: 280 files, 10.5MB
==> Installing libimobiledevice dependency: libplist
==> Downloading https://homebrew.bintray.com/bottles/libplist-2.1.0.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libplist-2.1.0.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/libplist/2.1.0: 29 files, 357.5KB
==> Installing libimobiledevice dependency: libtasn1
==> Downloading https://homebrew.bintray.com/bottles/libtasn1-4.15.0.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libtasn1-4.15.0.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/libtasn1/4.15.0: 60 files, 392.9KB
==> Installing libimobiledevice dependency: libusb
==> Downloading https://homebrew.bintray.com/bottles/libusb-1.0.23.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libusb-1.0.23.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/libusb/1.0.23: 29 files, 524.8KB
==> Installing libimobiledevice dependency: libusbmuxd
==> Downloading https://homebrew.bintray.com/bottles/libusbmuxd-2.0.1.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libusbmuxd-2.0.1.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/libusbmuxd/2.0.1: 14 files, 165.5KB
==> Installing libimobiledevice --HEAD
==> Cloning https://git.libimobiledevice.org/libimobiledevice.git
Cloning into '/Users/wushuang/Library/Caches/Homebrew/libimobiledevice--git'...
==> Checking out branch master
Already on 'master'
Your branch is up to date with 'origin/master'.
==> ./autogen.sh
==> ./configure --disable-silent-rules --prefix=/usr/local/Cellar/libimobiledevice/HEAD-297ae43_6 --without-cython --enable-debug-code
==> make install
🍺 /usr/local/Cellar/libimobiledevice/HEAD-297ae43_6: 68 files, 1.1MB, built in 4 minutes 2 seconds
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/wushuang/Library/Caches/Homebrew/coreutils--8.31.mojave.bottle.tar.gz... (3.8MB)
Removing: /Users/wushuang/Library/Logs/Homebrew/pkg-config... (64B)
Removing: /Users/wushuang/Library/Logs/Homebrew/libtool... (64B)
Removing: /Users/wushuang/Library/Logs/Homebrew/coreutils... (64B)
Removing: /Users/wushuang/Library/Logs/Homebrew/libksba... (64B)
Removing: /Users/wushuang/Library/Logs/Homebrew/libyaml... (64B)
Removing: /Users/wushuang/Library/Logs/Homebrew/readline... (64B)
Removing: /Users/wushuang/Library/Logs/Homebrew/libgpg-error... (64B)
Removing: /Users/wushuang/Library/Logs/Homebrew/zlib... (64B)
Removing: /Users/wushuang/Library/Logs/Homebrew/autoconf... (64B)
Removing: /Users/wushuang/Library/Logs/Homebrew/openssl@1.1... (64B)
Removing: /Users/wushuang/Library/Logs/Homebrew/automake... (64B)
Pruned 0 symbolic links and 2 directories from /usr/local
==> Caveats
==> sqlite
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.
If you need to have sqlite first in your PATH run:
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile
For compilers to find sqlite you may need to set:
export LDFLAGS="-L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/sqlite/include"
For pkg-config to find sqlite you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"
==> python
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
If you need Homebrew's Python 2.7 run
brew install python@2
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> libxml2
libxml2 is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have libxml2 first in your PATH run:
echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.bash_profile
For compilers to find libxml2 you may need to set:
export LDFLAGS="-L/usr/local/opt/libxml2/lib"
export CPPFLAGS="-I/usr/local/opt/libxml2/include"
For pkg-config to find libxml2 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"
wushuangdeMacBook-Pro:~ wushuang$ brew install ideviceinstaller ios-deploy cocoapods
==> Installing dependencies for ideviceinstaller: libzip
==> Installing ideviceinstaller dependency: libzip
==> Downloading https://homebrew.bintray.com/bottles/libzip-1.5.2.mojave.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring libzip-1.5.2.mojave.bottle.1.tar.gz
🍺 /usr/local/Cellar/libzip/1.5.2: 134 files, 579.5KB
==> Installing ideviceinstaller
==> Downloading https://homebrew.bintray.com/bottles/ideviceinstaller-1.1.0_4.mojave.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring ideviceinstaller-1.1.0_4.mojave.bottle.1.tar.gz
🍺 /usr/local/Cellar/ideviceinstaller/1.1.0_4: 8 files, 60.5KB
==> Downloading https://homebrew.bintray.com/bottles/ios-deploy-1.10.0.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring ios-deploy-1.10.0.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/ios-deploy/1.10.0: 7 files, 236.9KB
==> Downloading https://homebrew.bintray.com/bottles/cocoapods-1.8.4.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/d4/d43db56c6e712b2ea5349d1fd02cb60678d7becc2672921132408498aa20adc2?__gda__=exp=1578320187~hmac=b282968772b93ce2dabe64c9ad9d32e9a8bc59837e3
######################################################################## 100.0%
==> Pouring cocoapods-1.8.4.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pod
Target /usr/local/bin/pod
already exists. You may want to remove it:
rm '/usr/local/bin/pod'
To force the link and overwrite all conflicting files:
brew link --overwrite cocoapods
To list all files that would be deleted:
brew link --overwrite --dry-run cocoapods
Possible conflicting files are:
/usr/local/bin/pod
/usr/local/bin/xcodeproj
==> Summary
🍺 /usr/local/Cellar/cocoapods/1.8.4: 10,983 files, 18MB
wushuangdeMacBook-Pro:~ wushuang$ pod setup
五、下载VS Code并配置
1、安装 VS Code
2、安装Flutter插件 参照 安装Flutter插件