问题:
前段时间我上传自己的开源项目到 Cocoapods 的时候,由于依赖了 Masonry,当我执行下面的命令的时候一直报错:
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 的源码时,发现 AFNetworking 的 podspec 文件配置了 s.public_header_files 和s.source_files:
s.public_header_files = 'AFNetworking/AFNetworking.h'
s.source_files = 'AFNetworking/AFNetworking.h'
而这个 AFNetworking.h 是专门用来定义自己的宏以及导入其他类的头文件的,文件内容如图:
003于是我在自己的开源项目中也创建了一个 HeaderFiles.h,文件内容如图:
002文件路径如图:
001然后把 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
当我再次执行下面这个命令时:
pod spec lint HWAutoScrollView.podspec
居然通过验证了,苦于已久的问题终于被解决了😄😄😄。
2017-10-27 update
最近看到很多人说执行 pod 命令之后只有头文件,然后我把自己的项目跟一位网友的项目对比了一下,如图:
WX20171027-174055@2x.png大家把不同之处对照着改过来即可。
网上有很多上传开源项目到 Cocoapods 的教程,但是对依赖的第三方框架的配置说得都不够详细,Cocoapods 官网也是如此。希望这篇文章对大家有用。
如有不足,欢迎指正!
网友评论
MyLib git:(master) ✗ pod lib lint
-> MyLib (0.2.1)
- WARN | url: The URL (https://git.oschina.net/osc_hj/mylib) is not reachable.
- ERROR | [MyLib/View] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
- ERROR | [MyLib/View] xcodebuild: /Users/whj/Library/Developer/Xcode/DerivedData/App-bdlrjjjsynuexjhbmwqetlgsswnd/Build/Products/Release-iphonesimulator/MyLib/MyLib.framework/Headers/WBRefreshGifHeader.h:10:9: error: include of non-modular header inside framework module 'MyLib.WBRefreshGifHeader': '/Users/whj/Library/Developer/Xcode/DerivedData/App-bdlrjjjsynuexjhbmwqetlgsswnd/Build/Products/Release-iphonesimulator/MJRefresh/MJRefresh.framework/Headers/MJRefresh.h' [-Werror,-Wnon-modular-include-in-framework-module]
- NOTE | [MyLib/View] xcodebuild: /var/folders/cf/m0nst0fj1p3cps_vmf8fvs_m0000gn/T/CocoaPods/Lint/App/main.m:3:9: fatal error: could not build module 'MyLib'
[!] MyLib did not pass validation, due to 2 errors and 1 warning.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
You can use the `--no-clean` option to inspect any issue.
2.把你的错误信息帖出来看看吧