Flutter環境變量配置
1.下載Flutter SDK
-
一.、使用git克隆Flutter,命令:gitclone -b beta https://github.com/flutter/flutter.git;
-
二、從官網下載flutter,https://flutter.io/setup-macos/;
2.配置環境變量
在當前用戶目錄下創建.bash_profile文件,如果該文件已經存在,則直接打開.
打開配置文件
open -e .bash_profile
配置
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=/Users/hujintao/flutter/bin:$PATH
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/emulator
export RN=/usr/local/bin
export PATH=$RN:$PATH
GRADLE_HOME=/Users/Apple/Desktop/soft/gradle/gradle-4.6
export GRADLE_HOME
export PATH=$PATH:$GRADLE_HOME/bin
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
其他問題解決
終端執行命令flutter doctor
檢測安裝依賴
✗ 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.4)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Ultimate Edition (version 2018.1.4)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.35.1)
✗ Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
android studio 配置
解決方案:打開android studio, 打開plugin;
輸入flutter搜索,點擊中間的 Search in repositories;
需要安裝兩個插件:
- Flutter插件: 支持Flutter開發工作流 (運行、調試、熱重載等).
- Dart插件: 提供代碼分析 (輸入代碼時進行驗證、代碼補全等).
要安裝這些: - 點擊install,安裝完畢之后重啟android studio;
配置模擬器
成功的標志
3.創建新項目
Run the app
//終端下建個文件夾,用命令創建一個flutter項目
1. flutter create myapp
//進入項目
2. cd myapp
//run起來
3. flutter run
效果圖:
Android
iOS
運行在所有可用設備
flutter run -d all