Carthage使用(cocoapods的替代)

1.使用homebrew安裝Carthage
brew intsall carthage
 Ps:沒有安裝Homebrew的話,進入傳送門 Homebrew。順便提一句能夠選擇簡體中文啊。
 
2.進入項目建立
vim Cartfile 
 
Cartfile內容示例以下
  • >= 1.0 for 「at least version 1.0」 1.0以上
  • ~> 1.0 for 「compatible with version 1.0」 最好是1.0,
  • == 1.0 for 「exactly version 1.0」 必須是1.0
  • 什麼也不寫,默認是最新版本
# Require version 2.3.1 or later
github "ReactiveCocoa/ReactiveCocoa" >= 2.3.1

# Require version 1.x
github "Mantle/Mantle" ~> 1.0    # (1.0 or later, but less than 2.0)

# Require exactly version 0.4.1
github "jspahrsummers/libextobjc" == 0.4.1

# Use the latest version
github "jspahrsummers/xcconfigs"

# Use the branch
github "jspahrsummers/xcconfigs" "branch"

# Use a project from GitHub Enterprise
github "https://enterprise.local/ghe/desktop/git-error-translations"

# Use a project from any arbitrary server, on the "development" branch
git "https://enterprise.local/desktop/git-error-translations2.git" "development"

# Use a local project
git "file:///directory/to/project" "branch"

爲了簡單我只添加了一個 Ps:第一行爲註釋html

#Require version 2.0.0
github "Alamofire/Alamofire" ~> 2.0.0
 
3.終端運行
carthage update
 
運行carthage update的結果以下
 
*** Cloning Alamofire
*** Checking out Alamofire at "2.0.2"
*** xcodebuild output can be found in /var/folders/ps/vkznbcf51bd56ld8j4cby_5m0000gp/T/carthage-xcodebuild.kTo8yR.log
*** Building scheme "Alamofire watchOS" in Alamofire.xcworkspace
*** Building scheme "Alamofire OSX" in Alamofire.xcworkspace
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace

 

文件目錄以下
其中文件Cartfile、Cartfile.resolved 和 Carthage文件夾是與Carthage被建立出來的,其餘的項目自身帶的
 
4.打開 Carthage文件夾 進入Bulid。以iOS爲例,進入iOS文件夾找到Alamofire.framework拖到項目中
 
或者在項目中選中Target -> Build Phases -> Link Library with Librarie點擊+號,而後點擊左下角的add Other.. 找到。framework添加就行
 
5.添加腳本
在 Build Phases -> +(左上角) -> New Run Script Phase
而後,點開Run Script 添加腳本
/usr/local/bin/carthage copy-frameworks
最後添加"Input Files」(以Alamofire爲例)
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
以下圖所示:
 
 
添加的腳本的做用
在App Store提交通用二進制觸發bug時這個腳本將運行,保證在歸檔時必要的bitcode相關文件被拷貝。
This script works around an App Store submission bug triggered by universal binaries and ensures that necessary bitcode-related files are copied when archiving.
 
另外須要注意Carthage 支持OS X的各個版本,可是對於iOS只支持iOS 8及其以上
only officially supports dynamic frameworks. Dynamic frameworks can be used on any version of OS X, but only on iOS 8 or later.
 
最後附上Carthage的github地址: https://github.com/Carthage/Carthage
相關文章
相關標籤/搜索