Cocoa Pods 疑难杂症大杂烩

1.Setting up CocoaPods master repo

Setting up CocoaPods master repo 卡住
当pod setup 进入Setting up CocoaPods master repo 等待的时候表示正在下载了,此时你可通过新开一个终端窗口,输入"cd ~/.cocoapods/"命令行跳到cocoapods文件夹内,执行"du -sh *"查看正在下载的文件夹的大小
具体方法:

1.耐心等待

  1. cd /.cocoapods/
  2. du -sh *

2.None of your spec sources contain a spec satisfying the dependency

图1.png

发现这是个已知的BUG, CocoaPods的版本库是有缓存的, 但在使用pod指令更新版本库时会出现冲突, 导致更新并不能如期完成, 需要手动删除本地缓存, 再进行更新.

具体方法:

sudo rm -fr ~/.cocoapods/repos/master pod setup

3.in `find_spec_for_exe': can't find gem cocoapods

//问题出现
 ➜  MMAlipayDemo git:(master) ✗ pod init
/Library/Ruby/Site/2.0.0/rubygems.rb:250:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException)
    from /Library/Ruby/Site/2.0.0/rubygems.rb:278:in `activate_bin_path'
    from /usr/local/bin/pod:22:in `<main>'

解决方法:

sudo gem uninstall cocoapods
gem install cocoapods

4. Cocopods 遇到You don't have write permissions for the /usr/bin directory.

问题 升级pod的时候遇到 没有操作 /usr/bin 目录的权限
并且进行权限修改也无效果。

sudo gem update cocoapods --pre
Updating installed gems
Updating cocoapods
Fetching: concurrent-ruby-1.1.5.gem (100%)
Successfully installed concurrent-ruby-1.1.5
Fetching: httpclient-2.8.3.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.
sudo chmod 777 /usr/bin
Password:
chmod: Unable to change file mode on /usr/bin: Operation not permitted

解决方法:采用下方命令

sudo gem install cocoapods -n /usr/local/bin
pod --version
1.8.4 [升级完成]

5 操作repo

查看repo列表
pod repo list
删除repo
pod repo remove ******
更新repo
pod repo update

6 pod操作

更新pod
gem install cocoapods --pre
查看当前ruby源
gem sources

image.png

删除ruby源
gem sources --remove http://gems.ruby-china.org/
添加ruby源
gem sources -a https://gems.ruby-china.com/

7 CDN: error

[mumu]→ pod repo update --verbose
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because
checking is only perfomed in repo update

image.png

解决办法 参考
重装psych

[mumu] → sudo gem install psych
8 升级Cocoa Pod

命令

$ sudo gem update --system
9 pod repo update 失败
image.png

Updating spec repo cocoapods
[!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down

解决 安装 homebrew or 升级

 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
10 .debug.xcconfig: unable to open file (in target "" in project "**")

本地pod冲突, 重新进行pod update

11 RuntimeError - [Xcodeproj] Unknown object version

执行pod init失败

/Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.19.0/lib/xcodeproj/project.rb:227:in `initialize_from_file'
/Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.19.0/lib/xcodeproj/project.rb:112:in `open'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/command/init.rb:41:in `validate!'
/Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:333:in `run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `<main>'

原因是因为xcodeproj版本不一致
解决方案

gem uninstall xcodeproj
gem install xcodeproj
12 [!] The 'your project' target has transitive dependencies that include statically linked binaries: (your framework)

swift use_frameworks的问题。

解决方案
使用静态链接 在 podfile中添加
use_frameworks! :linkage => :static

13 /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:34:in `force_encoding': can't modify frozen String (FrozenError)

出错详解: Xcode14中 执行 pod init or pod install 报错。
原因: 应该是ruby版本不兼容
解决方案
1 升级ruby [未尝试]
2 更变xcode project Format 改成14以下即可

image.png

14 error: DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead (in target 'Firebase' from project 'Pods')

出错详情: xcode15: pod成功 编译报错
解决方案: 附带参考链接 fix xcode 15 DT_TOOLCHAIN_DIR - remove after fix oficially

post_install do |installer|
  installer.aggregate_targets.each do |target|
      target.xcconfigs.each do |variant, xcconfig|
      xcconfig_path = target.client_root + target.xcconfig_relative_path(variant)
      IO.write(xcconfig_path, IO.read(xcconfig_path).gsub("DT_TOOLCHAIN_DIR", "TOOLCHAIN_DIR"))
      end
  end

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if config.base_configuration_reference.is_a? Xcodeproj::Project::Object::PBXFileReference
          xcconfig_path = config.base_configuration_reference.real_path
          IO.write(xcconfig_path, IO.read(xcconfig_path).gsub("DT_TOOLCHAIN_DIR", "TOOLCHAIN_DIR"))
      end
    end
  end
end
15 RuntimeError - PBXGroup attempted to initialize an object with unknown ISA PBXFileSystemSynchronizedRootGroup from attributes: {"isa"=>"PBXFileSystemSynchronizedRootGroup", "exceptions"=>["65B3E67F2D9130FA00C63518"], "explicitFileTypes"=>{}, "explicitFolders"=>[], "path"=>"ChuanShanJiaTest", "sourceTree"=>"<group>"}

pod init or install 时报错。

RuntimeError - `PBXGroup` attempted to initialize an object with unknown ISA `PBXFileSystemSynchronizedRootGroup` from attributes: `{"isa"=>"PBXFileSystemSynchronizedRootGroup", "exceptions"=>["65B3E67F2D9130FA00C63518"], "explicitFileTypes"=>{}, "explicitFolders"=>[], "path"=>"ChuanShanJiaTest", "sourceTree"=>"<group>"}`
If this ISA was generated by Xcode please file an issue: https://github.com/CocoaPods/Xcodeproj/issues/new
/Users/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/xcodeproj-1.24.0/lib/xcodeproj/project/object.rb:359:in `rescue in object_with_uuid'
/Users/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/xcodeproj-1.24.0/lib/xcodeproj/project/object.rb:349:in `object_with_uuid'
/Users/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/xcodeproj-1.24.0/lib/xcodeproj/project/object.rb:300:in `block (2 levels) in configure_with_plist'
/Users/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/xcodeproj-1.24.0/lib/xcodeproj/project/object.rb:299:in `each'
/Users/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/xcodeproj-1.24.0/lib/xcodeproj/project/object.rb:299:in `block in configure_with_plist'
/Users/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/xcodeproj-1.24.0/lib/xcodeproj/project/object.rb:296:in `each'
/Users/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/xcodeproj-1.24.0/lib/xcodeproj/project/object.rb:296:in `configure_with_plist'
/Users/.rbenv/versions/2.6.10/lib/ruby/gems/2.6.0/gems/xcodeproj-1.24.0/lib/xcodeproj/project.rb:272:in `new_from_plist'

CocoaPods 的 xcodeproj 依赖库可能已经修复了这个问题,可以尝试升级:

gem install xcodeproj

然后检查版本:

gem list xcodeproj

如果仍然是 1.24.0,可以尝试强制更新:

sudo gem uninstall xcodeproj
sudo gem install xcodeproj -v 1.24.1  # 尝试安装最新版本

然后重新 init or install。

16 ArgumentError - [Xcodeproj] Unable to find compatibility version string for object version 70.
ArgumentError - [Xcodeproj] Unable to find compatibility version string for object version `70`.
/Users//.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/xcodeproj-1.27.0/lib/xcodeproj/project.rb:85:in `initialize'
/Users//.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/cocoapods-1.16.2/lib/cocoapods/project.rb:48:in `initialize'
/Users//.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/cocoapods-1.16.2/lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb:82:in `new'
/Users//.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/cocoapods-1.16.2/lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb:82:in `create_project'
/Users//.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/cocoapods-1.16.2/lib/cocoapods/installer/xcode/pods_project_generator/project_generator.rb:73:in `generate!'

可能是 xcode beta 版本的问题,xcodeproj 文件中的 objectVersion 版本过高。查看之前项目修改
YourProject.xcodeproj/project.pbxproj 中的 objectVersion 改为 54 或者 正常能运行的版本。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容