Mac Flutter安装与配置
一、获取Flutter SDK
(1)官网下载适用的SDK:https://flutter.dev/docs/development/tools/sdk/releases?tab=macos#macos
(2)解压SDK安装包
(3)配置环境变量
命令行输入:open .bash_profile
然后讲地址引用到文件中
export PATH=`你的flutter所在的文件夹路径`flutter/bin:$PATH
由于网络限制,建议把Flutter临时镜像加入,故完整代码应该是
#前两个是镜像地址,后面的`/flutter/bin:$PATH`是你clone的仓库地址,这里默认就是在你当前的系统路径中
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=/Users/Talon/Desktop/Tools/flutterSdk/flutter/bin:$PATH
二、安装
命令行中运行以下代码进行安装
flutter doctor
输出结果并没有成功
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.11.6 15G31, locale
zh-Hans)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
[!] Xcode - develop for iOS and macOS (Xcode 8.2.1)
✗ Flutter requires a minimum Xcode version of 9.0.0.
Download the latest version or update via the Mac App Store.
! CocoaPods out of date (1.6.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin
code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade:
brew upgrade cocoapods
pod setup
[✗] iOS tools - develop for iOS devices
✗ 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.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Community Edition (version 2018.2.4)
✗ 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 6 categories.
上面的信息可以看出
- flutter安装的版本
- Flutter运行所需的Android工具链,有些许可证没有接受
- XCode需要更新,IOS先跳过
- AS和IntelliJ 插件没有安装
- 没有设备链接
解决:
(1)接受许可
flutter doctor --android-licenses
一路输入 Y
(2)安装AS插件,安装完后重启AS。 注意 Flutter 和 Dart 两个插件都要安装!
并勾选 File>Settings>Plugs>Android APK Support
,确认并重启AS
三、第一个flutter程序
- 选择File>New Flutter Project
- 创建完成之后,启动即可。