参考官网:https://flutterchina.club/setup-macos
一、Flutter环境配置
1、使用镜像
mac终端编辑.bash_profile:
vi ~/.bash_profile
加入镜像路径:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
官网提供的临时镜像,参考获取最新镜像:
https://github.com/flutter/flutter/wiki
2、获取Flutter SDK
链接:https://github.com/flutter/flutter/releases
下载安装包并解压到想安装的目录:

3、编辑~/.bash_profile
添加flutter相关工具到path中:
export PATH=/Users/yanghaibo/flutter/flutter/bin:$PATH
设置后执行命令使配置生效:
source ~/.bash_profile
查看flutter是否在PATH中:
echo $PATH
4、运行flutter doctor命令查看是否需要安装其它依赖项来完成安装。

该命令还会扫描xcode、Android Studio、IntelliJ IDEA等如果Mac安装的有。开发中我使用的是:Android Studio。
5、安装Android Studio,打开偏好设置preference添加flutter、dart插件。
如下图:

安装完成运行flutter doctor检测是否安装成功:

安装完成。
二、使用Android Studio创建工程
1、安装完成之后打开Android Studio,会出现Start a new Flutter project选项:

2、点击选择Flutter Application创建新工程:

3、设置工程名称,使用下划线形式命名:

注意文件路径最好使用英文命名,否则会报编码错误问题。
4、点击下一步,点击Finish直接创建。

需要稍微等待一下。
5、创完成,首先没有设备模拟器,需要添加模拟器。

选择安装模拟器:

6、运行工程。
安卓模拟器运行:

选择苹果模拟器,使用的是xcode自带的模拟器:

三、使用命令创建工程
将flutter应用安装到iOS设备的工具
brew update
brew install --HEAD libimobiledevice
brew install ideviceinstaller ios-deploy cocoapods
pod setup
1、创建一个应用,注意不要大写
创建应用:
flutter create fiistapp
运行:
flutter run
多模拟器,需要选择模拟器运行:
flutter run -d 748770E3-83A2-4960-9B5D-9FD37EC7BE89
注意,如出现的错误:
ideviceinfo returned an error:
ERROR: Could not connect to lockdownd, error code -3
需要更新libimobiledevice和ideviceinstaller 最后授权一下即可
brew uninstall ideviceinstaller -g
brew uninstall libimobiledevice -g
brew install --HEAD libimobiledevice -g
brew install ideviceinstaller -g
sudo chmod -R 777 /var/db/lockdown
按照以上步骤卸载之前的ideviceinstaller和libimobiledevice 重新安装并授权即可
brew uninstall ideviceinstaller
brew uninstall libimobiledevice
brew install --HEAD libimobiledevice
brew link --overwrite libimobiledevice
brew install ideviceinstaller
brew link --overwrite ideviceinstaller
网友评论