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 設置全局環境變量

更改配置文件android

vi ~/.bash_profile

在上述文件末尾追加以下:ios

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

生效git

source ~/.bash_profile

完整的 .bash_profile 配置,包括安卓環境變量配置github

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驗證是否安裝成功

如下命令不報錯,就成功了macos

flutter

2 安裝插件

檢查插件安裝狀況android-studio

flutter doctor

結果可能以下:
bash

缺乏什麼按照提示,跑一下上面提示的命令便可,有的時間可能較長ide

2.1 Android插件

安裝android licences插件

flutter doctor --android-licenses

可能會報錯 SDKManager, 須要更新code

/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

相關文章
相關標籤/搜索