Flutter for iOS模拟器环境搭建

首先需要有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

 

posted on 2020-03-30 18:11  我来乔23  阅读(4515)  评论(0编辑  收藏  举报

导航