Mac 配置flutter
1.下载flutter的SDK,解压后放置随便路径
https://flutter.dev/docs/development/tools/sdk/releases?tab=macos
2.修改配置环境变量(路径为sdk解压后的放置路径)
vim ~/.bash_profile
//添加以下配置(/Users/mac/flutter是我的sdk解压路径)
export PATH=/Users/mac/flutter/bin:$PATH
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
:wq保存后 执行下 source ~/.bash_profile
3.检测环境
flutter -h 出现flutter帮助信息说明sdk安装配置成功
4.运行条件检测
flutter doctor 检测运行条件
一般需要依次运行以下命令:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
brew install ios-deploy
//如果brew update运行慢—————————————————————————
# 替换brew.git:
$ cd "$(brew --repo)"
# 中国科大:
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 清华大学:
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换homebrew-core.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
# 中国科大:
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 清华大学:
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 替换homebrew-bottles:
# 中国科大:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 清华大学:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 应用生效:
$ brew update
// —————————————————————————
完成后flutter doctor应该是这样的
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.4 18E227, 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.
[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
[!] Android Studio (not installed)
[✓] VS Code (version 1.34.0)
[✓] Connected device (1 available)
5 . 创建第一个flutter项目
cd 到项目文件夹后 使用flutter create xxxx_xxxx_xxx 即可 # 注意:项目名不能有大写字母!!!!!
6. 修改文件夹权限
sudo chmod -R 777 flutter_demo_01 //项目文件夹
sudo chmod -R 777 /Users/mac/flutter //sdk文件夹
7 .xcode 直接打开ios目录下的工程文件即可
8 .vscode 打开工程目录,运行flutter run即可。
R - 热更新
O- 安卓/ios切换
P-网格布局显示/隐藏
网友评论