一个Flutter&Cocoapods项目打包问题集锦
问题1 github加速问题
cocoapods项目需要访问https://github.com/CocoaPods/Specs.git,众所周知,github经常被墙,导致经常需要借助加速来下载和访问,这里可以使用油猴脚本或者Fastgithub浏览器插件来解决。我的解决方案是将Fastgithub的加速网址放到gitconfig文件中:
git config --global url."https://gitclone.com/github.com/CocoaPods/Specs.git".insteadOf "https://github.com/CocoaPods/Specs.git"
这个方案问题是,过一段时间加速器网址就不好使了,然后需要到浏览器中再通过“github加速”关键字再找一个加速网址。
问题2 ruby&cocoapods环境问题
遇到问题只能反复尝试安装和卸载ruby及cocoapods了,网上有的是方案。这里注意一下,可以通过GEM_HOME指定Ruby版本;cocopods有时候会遇到问题,需要创建好master和trunk repo。如果网络好的情况下,master和trunk可以直接通过git clone直接下载:
git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master
git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
如果不行,可以通过fastgithub直接访问https://github.com/CocoaPods/Specs.git的zip文件,然后解压到~/.cocoapods/repos目录下,再重命名为master或者trunk。
问题3 ruby安装不了3.0.0的版本可能跟openssl的版本有关系
这个时候,需要先安装好openssl,然后再去安装ruby。
问题4 业务问题:CocoaPods could not find compatible versions for pod “shared_preferences_foundation”
[!] CocoaPods could not find compatible versions for pod "shared_preferences_foundation":In Podfile:FlutterPluginRegistrant (from `../unifyapp_flutter_module/.ios/Flutter/FlutterPluginRegistrant`) was resolved to 0.0.1, which depends onshared_preferences_foundationshared_preferences_foundation (from `../unifyapp_flutter_module/.ios/.symlinks/plugins/shared_preferences_foundation/ios`)Specs satisfying the `shared_preferences_foundation (from `../unifyapp_flutter_module/.ios/.symlinks/plugins/shared_preferences_foundation/ios`), shared_preferences_foundation` dependency were found, but they required a higher minimum deployment target.
这个问题查的惨啊,各种尝试后,发现问题在于Flutter工程在执行flutter pub get后生成的.ios文件夹下面,Podfile中platform的 版本是9.0, 而cocoapods主工程中Podfile的版本为10.0.
解决办法就是:
1、 在flutter工程中,执行完
flutter pub get
以后,进入.ios隐藏目录,将Podfile的target版本修改为11.0,然后再执行:
flutter build ios --release --no-codesign
2、 然后进入cocoapods主工程,先把Podfile的平台版本也修改为 11.0. 然后执行:
pod install
至此,一个困扰了3天的问题,从持续集成人员手里完美解决。
记之。