前言
这里我们不在赘述网上一搜一大堆的单独项目上传 carthage ,在这篇文章中主要详细讲解下当你的项目依赖了其他三方库时候,如何上传到 carthage 供别人使用,并且同时支持上传到 cocoapods,并分享下carthage build --no-skip-current时候报的如下错误的解决方法
*** Skipped building ZLTestPods due to the error:
Dependency "ZLTestPods" has no shared framework schemes
步骤一
- 创建项目时,我们最好创建
Cocoa Touch Framework如图所示
Cocoa Touch Framework - 项目名字最好与你这个框架的名字一致(例如我的测试程序叫做
ZLTestPods) - 然后打开项目
File->New->Target创建一个single view app(可以叫做ZLTestPodsDemo之类的,这一部其实可以省略)
以下均以我的Demo名字
ZLTestPods举例
步骤二
因为我们要同时支持 cocoapods 和 carthage,所以我们的项目所依赖的第三方库需要用 carthage 集成进来。
例如我的测试项目依赖 SDWebImage,我们需要在项目目录下面创建 Cartfile,然后 vi Cartfile 并添加 github "rs/SDWebImage" 并执行 carthage update 或者 carthage update --platform ios
步骤三
打开你的项目,创建一个 Workspace。 File->New->Workspace,创建的这个文件放到你的项目根目录。
-
然后关掉你原来的项目,在
ZLTestPods.xcworkspace中把项目ZLTestPods.xcodeproj导入进来 (如果不知道怎么导入请自行搜索)
import -
导入三方框架,步骤同上,只不过文件位置在如图所示位置
步骤四
如图:

选中对应 scheme ,勾选 shared

步骤五
注:引用自http://shinancao.github.io/2017/07/16/Project-Design-4/,结尾会有声明该文章都参考了哪些资料
加入Travis CI
Travis可以对github上的项目进行持续构建,集成它的步骤也很简单,到官网注册:https://travis-ci.org/,进行github帐号关联,然后在项目里添加 .travis.yml 文件,在该文件中指定编译环境等
配置这个文件有几个要注意的坑:
- Travis默认使用xctool进行编译,但是xcode的版本指定的是8.0以上,xctool已经不支持了。需要指定用xcodebuild编译。
- /Users/travis/.travis/job_stages: line 156: shell_session_update: command not found这个错误可以忽略,如果编译失败,先排查一下其他问题。
- 如果用Carthage集成第三方库了,要进行Carthage的相关指定。
我的 .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编译成功

但是很不幸,我们得到了如下错误:
*** Skipped building ZLTestPods due to the error:
Dependency "ZLTestPods" has no shared framework schemes
但是我们在Manager schemes时候已经确定把ZLTestPods.framework勾选上了 shared。
这个问题可能是xcode的一个bug,问题在于.xcodeproj/xcshareddata/xcschemes/AHDownloadButton.xcscheme这个文件缺失,xcode并没有帮我们创建,解决方法也很简单,我们再次打开Manager schemes,取消勾选ZLTestPods.framework,然后在勾选上即可。然后再次执行carthage build --no-skip-current发现可以build成功了
参考链接: https://www.amerhukic.com/how-to-add-carthage-support-in-existing-cocoapod-project
步骤七
打tag,上传 github
执行 git tag 1.0.0,然后 git push --tags
上传后,可以新建个项目测试下,如下所示便是成功了

关于支持cocoapods
项目支持cocoapods,可以看下我这篇文章,有详细介绍
贴一下 ZLTestPods 的podspec 文件
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集成


