主要的原因就是 插件冲突了:cocoapods-pod-sign 和 cocoapods-packager 删除其中一个就可以了
sudo gem uninstall cocoapods-pod-sign
问题:
―― MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
### Command
```
/usr/local/bin/pod package FetaphonLib.podspec --force --no-mangle --exclude-deps --configuration=Release
```
### Report
* What did you do?
* What did you expect to happen?
* What happened instead?
### Stack
```
CocoaPods : 1.11.3
Ruby : ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin22]
RubyGems : 3.3.7
Host : macOS 13.0 (22A380)
Xcode : 14.0.1 (14A400)
Git : git version 2.37.3
Ruby lib dir : /Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib
Repositories : aliyun - git - https://github.com/aliyun/aliyun-specs.git @ 0d1b026fb5f8122364ca6e464956dbfededa6f75
edu-git-cocoapods-specs - git - https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git @ 124a10cb8c17146b7e642514841d424638d8fd55
master - git - https://github.com/CocoaPods/Specs.git @ 02472126ec89052e0d681ce2a0272f34b2e60c9a
trunk - CDN - https://cdn.cocoapods.org/
xiya-shinsson_appfront-ios-fetaphonlib - git - [email protected]:shinsson_appfront/iOS/fetaphonlib.git @ 7f63a7e68673a6e6c80ea3e9f11a8b18d6d29345
```
### Plugins
```
cocoapods-deintegrate : 1.0.5
cocoapods-packager : 1.5.0
cocoapods-plugins : 1.0.0
cocoapods-pod-sign : 1.3.0
cocoapods-search : 1.0.1
cocoapods-trunk : 1.6.0
cocoapods-try : 1.2.0
```
### Error
```
NoMethodError - undefined method `root_object' for nil:NilClass
target = aggregate_targets.first.user_project.root_object.targets.first
^^^^^^^^^^^^
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-pod-sign-1.3.0/lib/cocoapods-pod-sign/pod_installer.rb:52:in `pod_sign_extract_team_id_from_user_project'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-pod-sign-1.3.0/lib/cocoapods-pod-sign/pod_installer.rb:12:in `run_podfile_post_install_hook'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:933:in `block in run_podfile_post_install_hooks'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:149:in `message'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:932:in `run_podfile_post_install_hooks'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:331:in `block (2 levels) in create_and_save_projects'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pods_project_writer.rb:61:in `write!'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:330:in `block in create_and_save_projects'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:64:in `section'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:309:in `create_and_save_projects'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:301:in `generate_pods_project'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:180:in `integrate'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:167:in `install!'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-packager-1.5.0/lib/cocoapods-packager/pod_utils.rb:26:in `install_pod'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-packager-1.5.0/lib/pod/command/package.rb:79:in `build_in_sandbox'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-packager-1.5.0/lib/pod/command/package.rb:100:in `block in build_package'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-packager-1.5.0/lib/pod/command/package.rb:99:in `each'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-packager-1.5.0/lib/pod/command/package.rb:99:in `build_package'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-packager-1.5.0/lib/pod/command/package.rb:66:in `run'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in `run'
/Users/liuyihua/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/cocoapods-1.11.3/bin/pod:55:in `'
/usr/local/bin/pod:25:in `load'
/usr/local/bin/pod:25:in `'
```
――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
[!] Oh no, an error occurred.
Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=undefined+method+%60root_object%27+for+nil%3ANilClass%0A%0A++++++target+%3D+aggregate_targets.first.user_project.root_object.targets.first%0A+++++++++++++++++++++++++++++++++++++++++++++++++++%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E&type=Issues
If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new
Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md
Don't forget to anonymize any private data!
Looking for related issues on cocoapods/cocoapods...
- Pod installation failure on some transitive dependencies
https://github.com/CocoaPods/CocoaPods/issues/3267 [closed] [18 comments]
14 Nov 2018
- Is there a way/method to check if the Pods are installed using the `use_frameworks!` flag?
https://github.com/CocoaPods/CocoaPods/issues/3265 [closed] [7 comments]
05 Oct 2015
- CocoaPod install stuck
https://github.com/CocoaPods/CocoaPods/issues/3266 [closed] [1 comment]
15 Mar 2015
and 11471 more at:
https://github.com/cocoapods/cocoapods/search?q=undefined%20method%20%60root_object%27%20for%20nil%0A%0A%20%20%20%20%20%20target%20%3D%20aggregate_targets.first.user_project.root_object.targets.first%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E%5E&type=Issues&utf8=✓
解决办法:
对cocoapods进行重装即可:
卸载:
sudo gem uninstall cocoapods
并不能完全卸载掉,你可以通过如下命令查看 Cocoapods其余相关的组件
gem list --local | grep cocoapods
我的显示
cocoapods-core (1.11.2)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (1.5.1)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
cocoapods-try (1.2.0)
上面的各组件删除的话,需使用如下命令逐个删除,如
sudo gem uninstall cocoapods-core
重装命令
sudo gem install -n /usr/local/bin cocoapods
安装打包工具插件
安装打包工具 cocoapods-packager
sudo gem install cocoapods-packager
查看gem 相关配置信息,查找gem相关路径
gem environment
[
Xcode14 打包时不支持非 arm64的包,需要对打包文件进行修改
先找到文件 cocoapods-packager - > builder.rb
找到275行,将 ARCHS里的值,修改只支持arm64 即可
打包报错信息:
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: Pods/build/package.a and Pods/build-sim/package.a have the same architectures (arm64) and can't be in the same fat output file
解决办法:
找到你的打包插件中的pod_utils,rb 文件:
/你的路径/gems/cocoapods-packager-1.5.0/lib/cocoapods-packager/pod_utils.rb
在32行后面添加一行:
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
现在生成的包 是包含 模拟器和真机包