1.进入官网下载页:
https://flutter.dev/docs/development/tools/sdk/releases?tab=macos
可以看到有 Windows 、 macOS、 Linux 三种系统的下载包
点击macOS,然后点击下载 Stable channel (稳定版)中的最新版本,可以放先在桌面上,然后移到资源库Library中;
2.下载得到一个Flutter文件或者压缩包(解压缩即可),然后点击“访达”-“资源库”,把包拖到资源库;
3.app store 下载Xcode;
4.配置Path变量环境:
4.1 打开终端 Terminal,
然后输入
vi ~/.bash_profile
可能会报:
证明这个文件已经存在了,关闭终端重新打开,输入:open -e .bash_profile
open -e .bash_profile
然后在文件中添加:(如果 bash_profile无法编辑,输入 i 进入可编辑状态 )
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=你的flutter的存放路径/flutter/bin:$PATH
如果按照我的操作来的话,
export PATH=你的flutter的存放路径/flutter/bin:$PATH
其实就是:
export PATH=/Library/flutter/bin:$PATH
保存,退出( Esc : wq 保存退出)
4.2 执行下面这行命令,生效当前文件
source ~/.bash_profile
(如果你是用的是zsh,请参考https://www.jianshu.com/p/f9abb844e9b1中的这一步)
4.3 运行 flutter/bin 命令,验证目录是否在已经在PATH中:
echo $PATH
结果如下:
(注意:如果没有.bash_profile 文件,可以参考:https://blog.csdn.net/huxinguang_ios/article/details/78709428 创建)
4.4
执行 以下命令
flutter doctor
查看是否需要安装其它依赖项来完成安装。
如果在执行 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.
4.5然后再执行 以下命令查看配置
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 有一个成功就行,当然也可以再下载补全
5
5.1 安装 homebrew(如果已经安装homebrew就跳过)
可以点击homebrew 进去官网查看下载链接,也可以在Terminal 中执行
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
5.2 打开Terminal 然后逐条运行这些命令来安装用于将Flutter应用安装到iOS设备的工具
brew update
brew install --HEAD libimobiledevice
brew install ideviceinstaller ios-deploy cocoapods
pod setup
又是经过漫长的下载... (如果卡在 brew update这里,可以control+c终止,继续下一步就行了)
最后结果
至此,大功告成!
参考链接:
https://www.jianshu.com/p/f9abb844e9b1
https://www.jianshu.com/p/20519f2f0d36
https://www.jianshu.com/p/fb78a2b127df