遇坑背景
本人从github github.com/alibaba/flu…
遇到的问题
研究一下flutter ios端,导入已有的flutter时,升级了下xCode app (Version 14.3.1 (14E300c))后,ios项目运行编译报错如下:
Dart Warning: CocoaPods minimum required version 1.10.0 or greater not installed. Skipping pod install. CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see flutter.dev/platform-pl… To upgrade see guides.cocoapods.org/using/getti… for instructions. CocoaPods not installed or not in valid state. Error launching application on iPhone 14 Pro Max. #根据输入日志错误分析如下: CocoaPods minimum required version 1.10.0 or greater not installed. |
---|
意思是未安装CocoaPods最低要求版本1.10.0或更高版本。
问题分析猜测
打开CocoaPods Guides,sudo gem install cocoapods 一直报没权限,加上gem install cocoapods --user-install` 后报安装成功了,但是flutter doctor还是显示没安装,stackoverflow上大概都是
1. uninstall
2. install
3. flutter clean
4. flutter pub get
5. 重启IDE
6. flutter fun
以上全部不管用。
还有一个声音,是使用homebrew,brew install --cask cocoapods 依然卡住。链接如下。
很神奇,gem里的是1.12.1,而为什么显示的是1.12.1呢?需要注意的是,刚才homebrew下载的是 github.com/CocoaPods/C… github.com/CocoaPods/C… (1.12.1)。所以,为什么人们都说用cocoapods很难搞,这里可能看出 homebrew里用的是旧版本,而gem里是新的版本。
Dart Last login: Fri Sep 1 09:03:32 on console yp-220608@YP-220608deMacBook-Pro ~ % pod --version 1.8.4 yp-220608@YP-220608deMacBook-Pro ~ % which pod /opt/homebrew/bin/pod yp-220608@YP-220608deMacBook-Pro ~ % |
---|
结合上述链接描述,我先后逐步分析了安装路径是否正确,homebrew中的cocoapods是否是最新版本,查看环境配置情况。果然发现是pod和cocoapods没有配置环境变量导致的。
解决方案步骤如下:
1.首先卸载掉旧版本的homebrew中的cocoapods,因为它是错误的版本
2.通过gem which cocoapods
Dart yp-220608@YP-220608deMacBook-Pro ~ % gem which cocoapods /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin22/rbconfig.rb:21: warning: Insecure world writable dir /opt/homebrew/bin in PATH, mode 040777 |
---|
- 把pod和cocoapods加入到环境变量里
Dart export PATH="HOME/.local/share/gem/ruby/2.6.0/bin/:$HOME/.local/share/gem/ruby/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods.rb" |
---|
4.source ~/.zshrc (maybe .bashrc )
5.运行flutter doctor命令查看环境配置情况
Dart yp-220608@YP-220608deMacBook-Pro ~ % flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.13.0, on macOS 13.5 22G74 darwin-arm64 (Rosetta), locale zh-Hans-CN) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.3) [✓] VS Code (version 1.81.1) [✓] Connected device (3 available) [!] Network resources ✗ A cryptographic error occurred while checking "pub.dev/": Connection terminated during handshake** You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer. ✗ A network error occurred while checking "maven.google.com/": Operation timed out ✗ A network error occurred while checking "github.com/": Operation timed out **! Doctor found issues in 1 category. |
---|
6.执行Flutter clean,flutter pub get,flutter run命令选择ios设备运行项目。