iOS 技术文档收录iOS开发新发现技巧文字

Carthage安装及使用

2016-04-09  本文已影响12609人  靠谱丶活好
1.使用Homebrew安装Carthage之前,先对其进行更新,不然可能会安装到比较老的版本。

sudo brew update

2.安装Carthage
3.查看及升级Carthage版本
4.卸载Carthage

sudo brew uninstall carthage

5.创建空的Cartfile文件

touch Cartfile

6.使用Xcode命令打开Cartfile文件

open -a Xcode Cartfile

7.添加依赖库

例:github "Alamofire/Alamofire" ~> 3.0
- 版本的含义:
~>3.0:表示使用版本3.0以上但是低于4.0的最新版本,如3.5, 3.9。
==3.0:表示使用3.0版本。
>=3.0:表示使用3.0或更高的版本。
如果你没有指明版本号,则会自动使用最新的版本。

8.保存并关闭Cartfile文件并执行carthage update

执行update命令后,你的项目目录结构大致如下:


备注:
Cartfile利用xcode-select命令来编译Framework,如果你想用其他版的Xcode进行编译,执行下面这条命令,把xcode-select的路径改为另一版本Xcode就可以。
sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
9.引入Framework
  1. 设置Xcode自动搜索Framework的目录
  Target—>Build Setting—>Framework Search Path—>添加路径"$(SRCROOT)/Carthage/Build/iOS"

2. 添加编译的额外脚本
Target—>Build Phases —>”+”—>New Run Script Phase—>添加脚本"/usr/local/bin/carthage copy-frameworks"
3. 添加文件
Input Files—>添加路径"$(SRCROOT)/Carthage/Build/iOS/库名.framework"


以下是我安装时出现的一些错误。
错误1:

Error: Could not symlink bin/carthage
/usr/local/bin is not writable.
解决方案:
sudo brew remove carthage
sudo brew install carthage

错误2:

Warning: You are using OS X 10.11.
We do not provide support for this pre-release version.
You may encounter build failures or other breakage.
解决方案:
sudo brew update

错误3:

The following build commands failed:
CompileSwift normal arm64 /Users/XX/Carthage/Checkouts/Alamofire/Source/Timeline.swift
CompileSwift normal arm64 /Users/XX/Carthage/Checkouts/Alamofire/Source/Upload.swift
CompileSwift normal arm64 /Users/XX/Carthage/Checkouts/Alamofire/Source/ParameterEncoding.swift
CompileSwift normal arm64 /Users/XX/Carthage/Checkouts/Alamofire/Source/Request.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler(5 failures)
解决方案:
如果升级Carthage和brew都不行,可以升级下Xcode。

错误4:

dyld: Library not loaded: @rpath/xxx.framework/xxx
Referenced from: /var/mobile/Containers/Bundle/Application/0D926802-691A-49F6-A5A9-1AABB42BA5EB/carthageTest.app/carthageTest
Reason: image not found
解决方案:
在Embedded Binaries 中引入framework


上一篇 下一篇

猜你喜欢

热点阅读