cocoapods组件化遇到的问题
2018-11-06 本文已影响46人
Hanfank
搞了cocoapods组件化好几天了,刚入门就遇到问题,搞了一周,今天终于静下心来仔细揣摩。终于搞定了。记录下路程,给以后自己用,给别人用。
第一个问题:
使用 pod lib create XXX
指令,结果如法创建模版,错误提示如下
/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:27:in `<module:BuildSettingsArraySettingsByObjectVersion>': undefined method `to_set' for #<Array:0x007fbe0d0960c8> (NoMethodError)
Did you mean? to_s
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:8:in `<class:XCBuildConfiguration>'
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:4:in `<module:Object>'
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:3:in `<class:Project>'
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:2:in `<module:Xcodeproj>'
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb:1:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object/build_configuration.rb:194:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project/object.rb:521:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.8/lib/xcodeproj/project.rb:5:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/liuchuan/LAXCategoryKit/setup/ProjectManipulator.rb:30:in `run'
from /Users/liuchuan/LAXCategoryKit/setup/ConfigureiOS.rb:73:in `perform'
from /Users/liuchuan/LAXCategoryKit/setup/ConfigureiOS.rb:7:in `perform'
from /Users/liuchuan/LAXCategoryKit/setup/TemplateConfigurator.rb:85:in `run'
from ./configure:9:in `<main>'
To learn more about the template see `[https://github.com/CocoaPods/pod-template.git](https://github.com/CocoaPods/pod-template.git)`.
To learn more about creating a new pod, see `[http://guides.cocoapods.org/making/making-a-cocoapod](http://guides.cocoapods.org/making/making-a-cocoapod)`.
网上找了很多办法,终于找到一个和我一样问题的帖子:
http://www.cocoachina.com/bbs/read.php?tid-1742435.html
他在二楼贴了解决办法
解决了:
1.Clone this repo https://github.com/CocoaPods/Xcodeproj
2.gem build xcodeproj.gemspec
3.sudo gem install ./xcodeproj-.gem
刚开始我以为是命令,试了下行不通,正如帖子三楼中说的那样报错
原谅我知识不足。
实际上,上面说得不是命令,而是步骤。
- 第一步:是克隆通过git克隆项目,命令其实是下面这句
$ git clone https://github.com/CocoaPods/Xcodeproj
克隆下来后。 - 第二步:通过
gem
编译xcodeproj.gemspec
执行$ cd Xcodeproj
执行$ ls
命令可以看到以下目录
屏幕快照 2018-11-06 下午10.48.35.png
图中可以看到xcodeproj.gemspec
文件
执行$ gem build xcodeproj.gemspec
编译成功! - 最后一步:安装
xcodeproj-.gem
图中可以看到xcodeproj-1.7.0.gem
这也第三步骤中说的./xcodeproj-.gem
那么执行下面这句命令
$ sudo gem install xcodeproj-1.7.0.gem
这样就完成了。
然后再回到我们想要做的事情,回到你想要的目录下,执行pod lib create XXX
恭喜你!成功了!
如果还是不行,那一定会遇到下面这个问题
问题又来了!:
我在执行$ sudo gem install xcodeproj-1.7.0.gem
时提示权限不足:
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory.
于是我又开始找资料
终于在这个帖子中找到了方法
https://stackoverflow.com/questions/32810808/can-not-perform-pod-install-under-el-capitan-15a279b
按照上面答案说的那样sudo gem install -n /usr/local/bin cocoapods
我照葫芦画瓢输入了以下命令
$ sudo gem install -n /usr/local/bin xcodeproj-1.7.0.gem
终于执行成功。
接下来再回到我们想做的事情,回到你想要的目录下,执行pod lib create XXX
恭喜你!又成功了!