首先需要有Mac環境,請參考VMware 14安裝OS X10.11
其次需要XCode開發環境,請參考虛擬機macOS Mojave10.14安裝XCode10.1
最后參考官方文檔:https://flutter.cn/docs/get-started/install/macos
將flutter_macos_v1.12.13+hotfix.8-stable.zip拷貝至Mac OS10.11虛擬機,XCode安裝的是10.1,此時執行flutter doctor
Flutter v1.12.13版本最低需要一個Xcode11.0.0版本!
經驗證Flutter v1.9.1版本與Xcode10.1可以兼容。
更換版本后,執行flutter doctor,提示CocoaPods not installed!
安裝CocoaPods
1.刪除原來的ruby源:
gem sources --remove https://rubygems.org/
2.添加國內鏡像:
gem sources -a https://gems.ruby-china.com/ #保證訪問正常
3.更新gem源:
sudo gem update
4.安裝cocoapods:
sudo gem install cocoapods
5.pod安裝:
pod setup
可以看到No devices available
打開Xcode自帶的iOS虛擬機后(open -a Simulator或直接點擊程序塢中的模擬器圖標),即可識別Connected device
iOS模擬器運行flutter example hello_word
$ cd ./flutter/examples/hello_world
$ flutter run
Running "flutter pub get" in hello_world... 1.0s
Launching lib/main.dart on iPhone XR in debug mode...
Running Xcode build...
├─Assembling Flutter resources... 7.4s
└─Compiling, linking and signing... 58.9s
Xcode build done. 73.1s
Syncing files to device iPhone XR...
9,664ms (!)
🔥 To hot reload changes while running, press "r". To hot restart (and rebuild
state), press "R".
An Observatory debugger and profiler on iPhone XR is available at:
http://127.0.0.1:50297/sr6BSTwfCJ4=/
For a more detailed help message, press "h". To detach, press "d"; to quit,
press "q".
如果要在iOS真機上運行,還需要以下配置:
$ brew install --HEAD libimobiledevice
$ brew install ideviceinstaller
$ brew install ios-deploy
$ brew install cocoapods
$ pod setup
$ pod --version
$ pod repo update --verbose
最后執行flutter doctor檢查環境是否配置好!
由於我沒有iphone真機,所以不再詳細說明,請參考官方文檔:https://flutter.cn/docs/get-started/install/macos