Xcode 14 iOS pod package 报错打包报错信息 NoMethodError - undefined method `root_object' for nil:NilClas...

主要的原因就是 插件冲突了: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 - git@gitlab.xiya.local: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 `<top (required)>'
/usr/local/bin/pod:25:in `load'
/usr/local/bin/pod:25:in `<main>'
```

――― 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

[
image-20221101102754607.png

Xcode14 打包时不支持非 arm64的包,需要对打包文件进行修改

先找到文件 cocoapods-packager - > builder.rb

image-20221101104437833.png

找到275行,将 ARCHS里的值,修改只支持arm64 即可

image-20221101103152809.png

打包报错信息:

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

image-20221101104403113.png

在32行后面添加一行:

config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
image-20221101104324074.png

现在生成的包 是包含 模拟器和真机包


image-20221101105044557.png

参考链接:

1、IOS pod package 报错:Pods/build/package.a and Pods/build-sim/package.a have the same architectures

2、重装cocoapods

3、Mac M1芯片使用cocoa pods 系统自带Ruby2.6报错 从新安装Ruby(Homebrew)

4、CocoaPods 无法使用(Xcode 14.0)

5、系统更新导致ruby和cocoapods无法兼容经验总结

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,098评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,213评论 2 380
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,960评论 0 336
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,519评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,512评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,533评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,914评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,574评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,804评论 1 296
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,563评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,644评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,350评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,933评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,908评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,146评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,847评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,361评论 2 342

推荐阅读更多精彩内容