Flutter for iOS模拟器环境搭建 - 我来乔23

时间:2024-02-23 13:34:34

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 (!)