Carthage 安装使用

Carthage 安装使用
1.使用Homebrew安装Carthage之前,先对其进行更新,不然可能会安装到比较老的版本。
sudo brew update

2.安装Carthage
方法1
sudo brew install carthage (这种方式较好)
方法2
下载安装Carthage.pkg(国内基本下不下来)
方法3
下载Carthage,运行make install。

3.查看及升级Carthage版本
查看:carthage version
升级:brew upgrade 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命令后,你的项目目录结构大致如下:


Carthage 安装使用_第1张图片

Cartfile:文件用来标注你需要哪些依赖库,对应版本或者 Git 分支(需要提交到 Git)。
Cartfile.resolved:文件用来跟踪项目当前所用的依赖版本号,为了保持多端开发一致(需要提交到 Git)。
Carthage:文件夹用来存放依赖库的源文件和编译后的文件(不需要提交到 Git,可以修改.gitignore文件,增加忽略 Carthage 文件夹就行了:#Carthage Carthage)。

备注:
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"
Carthage 安装使用_第2张图片
  1. 添加编译的额外脚本 Target—>Build Phases —>”+”—>New Run Script Phase—>添加脚本"/usr/local/bin/carthage copy-frameworks" 3. 添加文件 Input Files—>添加路径"$(SRCROOT)/Carthage/Build/iOS/库名.framework"
Carthage 安装使用_第3张图片

以下是我安装时出现的一些错误。
错误1:
Error: Could not symlink bin/carthage/usr/local/bin is not writable.解决方案:sudo brew remove carthagesudo 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.swiftCompileSwift normal arm64 /Users/XX/Carthage/Checkouts/Alamofire/Source/Upload.swiftCompileSwift normal arm64 /Users/XX/Carthage/Checkouts/Alamofire/Source/ParameterEncoding.swiftCompileSwift normal arm64 /Users/XX/Carthage/Checkouts/Alamofire/Source/Request.swiftCompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler(5 failures)解决方案:如果升级Carthage和brew都不行,可以升级下Xcode。

你可能感兴趣的:(Carthage 安装使用)