flutter 环境搭建
1.安装flutter
1.1 下载flutter 包
cd Documents
git clone https://github.com/flutter/flutter.git
unzip ~/Documents/flutter_macos_v1.0.0-stable
1.2 设置全局环境变量
更改配置文件
vi ~/.bash_profile
在上述文件末尾追加如下:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=~/Documents/flutter/bin:$PATH
生效
source ~/.bash_profile
完整的 .bash_profile 配置,包括安卓环境变量配置
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
export CLASS_PATH=$JAVA_HOME/lib:$CLASS_PATH
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=~/Documents/flutter/bin:$PATH
1.3验证是否安装成功
以下命令不报错,就成功了
flutter
2 安装插件
检查插件安装情况
flutter doctor
结果可能如下:
缺少什么按照提示,跑一下上面提示的命令即可,有的时间可能较长
2.1 Android插件
安装android licences
flutter doctor --android-licenses
可能会报错 SDKManager, 需要更新
/Users/sw/Library/Android/sdk/tools/bin/sdkmanager --update
上面可能有 警告说 ~/.android/repositories.cfg not loaded, 然后一直卡住不动
touch ~/.android/repositories.cfg
最后重新新执行 flutter doctor --android-licenses 即可
2.2 iOS 插件
安装 libimobiledevice and ideviceinstaller
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
安装 ios-deploy
brew install ios-deploy
升级cocoapods
brew upgrade cocoapods
pod setup
3 android studio 插件
Preferences -> Plugins -> 选择 Browse repositories…, 选择 Dart/Flutter 插件并点击 install,
重启Android studio
File -> new Flutter Project 就可以创建Flutter 工程了, 如果没有出现,重装 Android Support API, Dart, Flutter, 重启AS