美文网首页iOSios
如何解决上传依赖Masonry的开源项目到Cocoapods时报

如何解决上传依赖Masonry的开源项目到Cocoapods时报

作者: 93b3d3ccb7e6 | 来源:发表于2016-10-10 16:13 被阅读1554次

    问题:

    前段时间我上传自己的开源项目到 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

    大家把不同之处对照着改过来即可。

    我的项目地址:https://github.com/hw20101101/HWAutoScrollView_OC


    网上有很多上传开源项目到 Cocoapods 的教程,但是对依赖的第三方框架的配置说得都不够详细,Cocoapods 官网也是如此。希望这篇文章对大家有用。
    如有不足,欢迎指正!

    相关文章

      网友评论

      • Mcyboy007:谢谢,我也遇到同样的问题,加了头文件的路径解决了!!!!
      • fcb856a4cf0e:你好,我这边也依赖MJRefresh框架,pod lib lint 的时候报同样的错,请问怎么解决?你这没太看懂
        93b3d3ccb7e6:@H了个J https://git.oschina.net/osc_hj/mylib 这个是私有的项目吗?
        fcb856a4cf0e:@明镜亦非台_ 项目是OC的;
        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.
        93b3d3ccb7e6:1.你的项目是基于swift还是OC?
        2.把你的错误信息帖出来看看吧
      • 小道萧兮:你好,我遇到同样的问题,只不过是用swift写的框架,依赖于pod导入的SDWebImage,请问如何解决?
        Scott_Mr:@季末微夏 我也是一样,只剩下一个头文件了。
        季末微夏:pod 下来就只有一个 HeaderFiles.h文件
        93b3d3ccb7e6:不好意思,我还没有研究过swift版

      本文标题:如何解决上传依赖Masonry的开源项目到Cocoapods时报

      本文链接:https://www.haomeiwen.com/subject/gecvyttx.html