首先,如果從未在MacOS上運行過Flutter應用,當首次安裝AndroidStudio并配置完Flutter環境后,創建FlutterProject并運行在IOS模擬器上時,很可能會報錯:
CocoaPods not installed...
此時需要安裝CocoaPods:
$ sudo gem install cocoapods
但本人在安裝時,一直失敗:
Failed to build gem native extension...
對本人有效的解決辦法:
1.更換homebew源:
$ /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

選擇5阿里巴巴源,
2.如提示是否執行,輸入Y,確定,
3.如提示輸入密碼,則輸入自己設定的系統密碼,確定,
4.更新ruby版本,先替換rvm源:
移除國外源:
$ gem sources --remove https://rubygems.org/
添加國內源:
$ gem sources -a https://gems.ruby-china.com/
安裝最新版ruby:
$ rvm install 3.0.2
此時,再次執行cocoapods的安裝:
$ sudo gem install cocoapods
此時很快就會安裝完畢!
如果我們的Flutter專案是在windows上創建的,并一直運行的安卓環境,當把專案轉移至Mac上想編譯IOS應用,同樣會遇到各種問題,這里的解決辦法是,我們在mac上匯入Flutter專案后:

洗掉以上檔案,以及IOS檔案夾下的build和Pods目錄,如果有的話,然后打開pubspec.yaml,執行pub get!
最后打開ios模擬器,并運行專案,flutter會自動編譯ios運行環境!
如果提示:
The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99
則可以打開ios下的Podfile檔案,
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
添加:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
end
end
end
如果提示:
The application's Info.plist does not contain CFBundleVersion.
則打開info.plist將CFBundleVersion版本號改為固定值即可!


轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/294254.html
標籤:其他
上一篇:面試總結——Android篇
下一篇:這樣學TS,遲早進大廠!!
