[整理总结] 让你的项目支持carthage

2018-07-09  本文已影响63人  奴良

前言

这里我们不在赘述网上一搜一大堆的单独项目上传 carthage ,在这篇文章中主要详细讲解下当你的项目依赖了其他三方库时候,如何上传到 carthage 供别人使用,并且同时支持上传到 cocoapods

步骤一

以下均以我的Demo名字 ZLTestPods 举例

步骤二

因为我们要同时支持 cocoapodscarthage,所以我们的项目所依赖的第三方库需要用 carthage 集成进来。

例如我的测试项目依赖 SDWebImage,我们需要在项目目录下面创建 Cartfile,然后 vi Cartfile 并添加 github "rs/SDWebImage" 并执行 carthage update 或者 carthage update --platform ios

步骤三

打开你的项目,创建一个 WorkspaceFile->New->Workspace,创建的这个文件放到你的项目根目录。

步骤四

如图:


Manage Schemes

选中对应 scheme ,勾选 shared

shared

步骤五

注:引用自http://shinancao.github.io/2017/07/16/Project-Design-4/,结尾会有声明该文章都参考了哪些资料

加入Travis CI

Travis可以对github上的项目进行持续构建,集成它的步骤也很简单,到官网注册:https://travis-ci.org/,进行github帐号关联,然后在项目里添加 .travis.yml 文件,在该文件中指定编译环境等

配置这个文件有几个要注意的坑:

我的 .travis.yml 文件如下

language: objective-c
osx_image: xcode9.3
xcode_workspace: ZLTestPods
xcode_scheme: ZLTestPods
xcode_sdk: iphonesimulator11.3
before_install:
  - xcodebuild -showsdks
  - brew update
  - brew outdated carthage || brew upgrade carthage
before_script:
  - carthage bootstrap
before_deploy:
  - carthage build --no-skip-current
  - carthage archive $FRAMEWORK_NAME
script:
    - xcodebuild clean build -sdk iphonesimulator11.3 -workspace ZLTestPods.xcworkspace -scheme ZLTestPods CODE_SIGNING_REQUIRED=NO

步骤六

执行 `carthage build --no-skip-current,如果得到如下结果,便说明carthage编译成功

build

步骤七

打tag,上传 github
执行 git tag 1.0.0,然后 git push --tags

上传后,可以新建个项目测试下,如下所示便是成功了


update

关于支持cocoapods

项目支持cocoapods,可以看下我这篇文章,有详细介绍
贴一下 ZLTestPodspodspec 文件

Pod::Spec.new do |s|
  s.name         = 'ZLTestPods'
  s.version      = '0.1.9'
  s.summary      = 'test dependency'
  s.homepage     = 'https://github.com/longitachi/ZLTestPods'
  s.license      = 'MIT'
  s.platform     = :ios
  s.author       = {'longitachi' => 'longitachi@163.com'}
  s.ios.deployment_target = '9.0'
  s.source       = {:git => 'https://github.com/longitachi/ZLTestPods.git', :tag => s.version}
  s.source_files = 'ZLTestPods/TestFolder/**/*.{h,m}'
  s.dependency 'SDWebImage'
  s.requires_arc = true
end

后言

carthage 还是裁了不少坑的,现在又遇到一个新坑,就是 carthage 安装 GPUImage 时候会报错,暂时还没有解决,后续搜到解决办法后会继续分享。

感谢如下文章:
使开源库同时支持CocoaPods和Carthage集成

上一篇 下一篇

猜你喜欢

热点阅读