問(wèn)題:
前段時(shí)間我上傳自己的開源項(xiàng)目到 Cocoapods 的時(shí)候遍尺,由于依賴了 Masonry删性,當(dāng)我執(zhí)行下面的命令的時(shí)候一直報(bào)錯(cuò):
pod spec lint HWAutoScrollView.podspec
-> HWAutoScrollView (0.1.2)
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
- ERROR | xcodebuild: HWAutoScrollView/HWAutoScrollView/HWAutoScrollView.m:91:40: error: expected ')'
- NOTE | xcodebuild: HWAutoScrollView/HWAutoScrollView/HWAutoScrollView.m:91:39: note: to match this '('
- WARN | xcodebuild: HWAutoScrollView/HWAutoScrollView/HWAutoScrollView.m:91:38: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
- ERROR | xcodebuild: HWAutoScrollView/HWAutoScrollView/HWAutoScrollView.m:92:13: error: use of undeclared identifier 'make'
- ERROR | xcodebuild: HWAutoScrollView/HWAutoScrollView/HWAutoScrollView.m:91:22: error: no visible @interface for 'UIScrollView' declares the selector 'makeConstraints:'
解決方法:
直到我昨天看 AFNetworking 的源碼時(shí)锈死,發(fā)現(xiàn) AFNetworking 的 podspec 文件配置了 s.public_header_files 和s.source_files:
s.public_header_files = 'AFNetworking/AFNetworking.h'
s.source_files = 'AFNetworking/AFNetworking.h'
而這個(gè) AFNetworking.h 是專門用來(lái)定義自己的宏以及導(dǎo)入其他類的頭文件的,文件內(nèi)容如圖:
于是我在自己的開源項(xiàng)目中也創(chuàng)建了一個(gè) HeaderFiles.h,文件內(nèi)容如圖:
文件路徑如圖:
然后把 HeaderFiles.h 配置到 podspec 文件中,我的 podsoec 文件如下:
Pod::Spec.new do |s|
s.name = "HWAutoScrollView"
s.version = "0.0.3"
s.summary = "OC版廣告輪播視圖工具類"
s.homepage = "https://github.com/hwtest/HWAutoScrollViewDemo"
s.license = "MIT"
s.author = { "hwtest" => "hwtest@gmail.com" }
s.platform = :ios, "7.0"
s.source = { :git => "https://github.com/hwtest/HWAutoScrollViewDemo.git", :tag => "#{s.version}" }
s.source_files = "HWAutoScrollView", "HWAutoScrollView/**/*.{h,m}"
s.exclude_files = "HWAutoScrollView/Exclude"
s.framework = "UIKit"
s.requires_arc = true
s.public_header_files = 'HWAutoScrollView/HeaderFiles.h'
s.source_files = 'HWAutoScrollView/HeaderFiles.h'
s.dependency "Masonry"
end
當(dāng)我再次執(zhí)行下面這個(gè)命令時(shí):
pod spec lint HWAutoScrollView.podspec
居然通過(guò)驗(yàn)證了瓮钥,苦于已久的問(wèn)題終于被解決了??????。
2017-10-27 update
最近看到很多人說(shuō)執(zhí)行 pod 命令之后只有頭文件烹吵,然后我把自己的項(xiàng)目跟一位網(wǎng)友的項(xiàng)目對(duì)比了一下碉熄,如圖:
大家把不同之處對(duì)照著改過(guò)來(lái)即可。
我的項(xiàng)目地址:https://github.com/hw20101101/HWAutoScrollView_OC
網(wǎng)上有很多上傳開源項(xiàng)目到 Cocoapods 的教程年叮,但是對(duì)依賴的第三方框架的配置說(shuō)得都不夠詳細(xì)具被,Cocoapods 官網(wǎng)也是如此。希望這篇文章對(duì)大家有用只损。
如有不足,歡迎指正!