A simple, decentralized dependency manager for Cocoa.
- Create a Cartfile that lists the frameworks you’d like to use in your project.
- Run Carthage, which fetches and builds each framework you’ve listed.
- Drag the built
.framework
binaries into your application’s Xcode project.
Differences between Carthage and CocoaPods
xcodebuild
, but leaves the responsibility of integrating them up to the user. CocoaPods’ approach is easier to use, while Carthage’s is flexible and unintrusive.… to improve discoverability of, and engagement in, third party open-source libraries, by creating a more centralized ecosystem.
xcodebuild
to build dependencies, instead of integrating them into a single workspace, it doesn’t have a similar specification file but your dependencies must include their own Xcode project that describes how to build their products.Installing Carthage
carthage
tool on your system, please download and run the Carthage.pkg
file for the latest release, then follow the on-screen instructions.carthage
tool on your system simply by running brew update
and brew install carthage
. (note: if you previously installed the binary version of Carthage, you should delete /Library/Frameworks/CarthageKit.framework
).master
branch of the repository, then run make install
.Adding frameworks to an application
Getting started
If you're building for OS X
- Create a Cartfile that lists the frameworks you’d like to use in your project.
- Run
carthage update
. This will fetch dependencies into a Carthage/Checkouts folder and build each one. - On your application targets’ “General” settings tab, in the “Embedded Binaries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.
- On your application target’s “Build Phases” settings tab, click the “+” icon and choose “New Copy Files Phase”.
- Click the “Destination” drop-down menu and select “Products Directory”.
- For each framework you’re using, drag and drop its corresponding dSYM file.
If you're building for iOS, tvOS, or watchOS
- Create a Cartfile that lists the frameworks you’d like to use in your project.
- Run
carthage update
. This will fetch dependencies into a Carthage/Checkouts folder, then build each one. - On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.
- On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script in which you specify your shell (ex:
bin/sh
), add the following contents to the script area below the shell:/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input Files”, e.g.:$(SRCROOT)/Carthage/Build/iOS/Box.framework $(SRCROOT)/Carthage/Build/iOS/Result.framework $(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework
This script works around an App Store submission bug triggered by universal binaries and ensures that necessary bitcode-related files and dSYMs are copied when archiving.
.xcarchive
bundle.For both platforms
carthage bootstrap
to get started with the frameworks you’ve added.Adding frameworks to unit tests or a framework
@loader_path/Frameworks
to the "Runpath Search Paths" if it isn't already present.Upgrading frameworks
carthage update
command again.update
command. e.g.carthage update Box
carthage update Box Result
Nested dependencies
Using submodules for dependencies
carthage update
or carthage checkout
with the --use-submodules
flag..gitmodules
and .git/config
files, and automatically update the submodules when the dependencies’ versions change.Automatically rebuilding dependencies
/usr/local/bin/carthage build --platform "$PLATFORM_NAME" --project-directory "$SRCROOT"
Bash/Zsh/Fish completion
Supporting Carthage for your framework
Share your Xcode schemes
.xcodeproj
. You can see if all of your intended schemes build successfully by running carthage build --no-skip-current
, then checking the Carthage/Build folder.Resolve build failures
carthage build --no-skip-current
, try running xcodebuild -scheme SCHEME -workspace WORKSPACE build
or xcodebuild -scheme SCHEME -project PROJECT build
(with the actual values) and see if the same failure occurs there. This should hopefully yield enough information to resolve the problem.xcode-select
to change which version Carthage uses.Tag stable releases
v1.2
, the semantic version is 1.2.0.1.2-alpha-1
) are currently unsupported, and will be ignored.Archive prebuilt frameworks into one zip file
.framework
in its name (e.g., ReactiveCocoa.framework.zip
), to indicate to Carthage that it contains binaries.carthage archive
command as follows:carthage build --no-skip-current
carthage archive YourFrameworkName
Use travis-ci to upload your tagged prebuild frameworks
- Install travis CLI with
gem install travis
- Setup travis-ci for your repository (Steps 1 and 2)
- Create
.travis.yml
file at the root of your repository based on that template. SetFRAMEWORK_NAME
to the correct value.Replace PROJECT_PLACEHOLDER and SCHEME_PLACEHOLDERIf you are using a workspace instead of a project remove the xcode_project line and uncomment the xcode_workspace line.The project should be in the format: MyProject.xcodeprojThe workspace should be in the format: MyWorkspace.xcworkspaceFeel free to update thexcode_sdk
value to another SDK, note that testing on iphoneos SDK would require you to upload a code signing identityFor more informations you can visit travis docs for objective-c projectslanguage: objective-c osx_image: xcode7.3 xcode_project: <PROJECT_PLACEHOLDER> # xcode_workspace: <WORKSPACE_PLACEHOLDER> xcode_scheme: <SCHEME_PLACEHOLDER> xcode_sdk: iphonesimulator9.3 env: global: - FRAMEWORK_NAME=<THIS_IS_A_PLACEHOLDER_REPLACE_ME> before_install: - brew update - brew outdated carthage || brew upgrade carthage before_script: # bootstrap the dependencies for the project # you can remove if you don't have dependencies - carthage bootstrap before_deploy: - carthage build --no-skip-current - carthage archive $FRAMEWORK_NAME
- Run
travis setup releases
, follow documentation hereThis command will encode your github credentials into the .travis.yml file in order to let travis upload the release to github.com When prompted for the file to upload, enter $FRAMEWORK_NAME.framework.zip - Update the deploy section to run on tags:In
.travis.yml
locate:on: repo: repo/repo
And addtags: true
andskip_cleanup: true
:skip_cleanup: true on: repo: repo/repo tags: true
That will let travis know to create a deployment when a new tag is pushed and prevent travis to cleanup the generated zip file
Declare your compatibility
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
Known issues
Carthage/Build
directory into source control or use .framework release binaries. Instead, create a Run Script build phase in your Xcode project which calls carthage build
(optionally wrap this in a check for the existence of the Carthage/Build/
directory to avoid long build times due to recompiling dependencies unnecessarily.)Compile Errors
Module file was created by an older (newer) version of the compiler
... it may be that Carthage downloaded and used an existing compiled binary from the remote repo which is not compatible with the local machine.--no-use-binaries
to the carthage bootstrap/build/update
command. For example: carthage bootstrap --no-use-binaries
CarthageKit
carthage
command line tool is actually encapsulated in a framework named CarthageKit.Carthage使用
最近使用 Xcode8
适配 iOS10
,CocoaPods
暴露出很多问题,于是在新版本中尝试使用 Carthage
进行包管理,这里仅记录使用方法。
安装方法:
- 官方给出了
Homebrew
的安装方法,不过有一句要注意:
Alternatively only on Xcode 7.x, you can use Homebrew and install the carthage tool on your system simply by running brew update and brew install carthage.
基于上述,我们采用直接下载安装 Carthage.pkg.
使用方法:
和 CocoaPods
不同的时我没有找到类似 pod search xxx
的搜索方法,目前只有在 Github 的库主页找到相应的版本号。
cd
到项目目录下。vim Cartfile
以
Alamofire 4.0
为例,写入
Input Files—>添加路径"$(SRCROOT)/Carthage/Build/iOS/库名.framework"
这样就可以在项目哪正常使用了。管理版本和删除更改也很方便,推荐使用。
10.12 更新:
发现 Carthage
编译的 .framework
文件不支持 @IBInspectable
和 @IBDesignable
……有点蛋疼。 在使用类似 IBAnimatable
类似框架时,无法在 storyboard
/xib
进行操作。
如果要使自己的开源轮子支持
Carthage
, 参见github "Alamofire/Alamofire" ~> 4.0 |
保存退出。
运行 carthage update --platform ios
。 --platform ios
可以免除等待编译可能有的 OS X
tvOS
包的等待时间。
没有错误的话基本上目录结构如图,多说一句,在我运行 update
命令是有很多和 Xcode7
插件相关的警告 log 信息,我选择到 ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/
目录下删除所有插件。
Cartfile:文件用来标注你需要哪些依赖库,对应版本或者 Git 分支(需要提交到 Git)。
Cartfile.resolved:文件用来跟踪项目当前所用的依赖版本号,为了保持多端开发一致(需要提交到 Git)。
Carthage:文件夹用来存放依赖库的源文件和编译后的文件(不需要提交到 Git,可以修改.gitignore文件,增加忽略 Carthage 文件夹就行了。
设置Xcode自动搜索Framework的目录:
Target—>Build Setting—>Framework Search Path—>添加路径"$(SRCROOT)/Carthage/Build/iOS" |
添加编译的额外脚本:
Target—>Build Phases —>”+”—>New Run Script Phase—>添加脚本"/usr/local/bin/carthage copy-frameworks" |
添加文件:
Input Files—>添加路径"$(SRCROOT)/Carthage/Build/iOS/库名.framework"
这样就可以在项目哪正常使用了。管理版本和删除更改也很方便,推荐使用。
10.12 更新:
发现 Carthage
编译的 .framework
文件不支持 @IBInspectable
和 @IBDesignable
……有点蛋疼。 在使用类似 IBAnimatable
类似框架时,无法在 storyboard
/xib
进行操作。
如果要使自己的开源轮子支持
Carthage
, 参见: