Carthage安裝及使用

1.使用Homebrew安裝Carthage之前,先對(duì)其進(jìn)行更新,不然可能會(huì)安裝到比較老的版本。

sudo brew update

2.安裝Carthage
  • 方法1
    sudo brew install carthage
  • 方法2
    下載安裝Carthage.pkg
  • 方法3
    下載Carthage,運(yùn)行make install。
3.查看及升級(jí)Carthage版本
  • 查看:carthage version
  • 升級(jí):brew upgrade carthage
4.卸載Carthage

sudo brew uninstall carthage

5.創(chuàng)建空的Cartfile文件

touch Cartfile

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

open -a Xcode Cartfile

7.添加依賴庫(kù)

例:github "Alamofire/Alamofire" ~> 3.0
- 版本的含義:
~>3.0:表示使用版本3.0以上但是低于4.0的最新版本,如3.5, 3.9。
==3.0:表示使用3.0版本。
>=3.0:表示使用3.0或更高的版本。
如果你沒有指明版本號(hào),則會(huì)自動(dòng)使用最新的版本。

8.保存并關(guān)閉Cartfile文件并執(zhí)行carthage update

執(zhí)行update命令后,你的項(xiàng)目目錄結(jié)構(gòu)大致如下:


  • Cartfile:文件用來標(biāo)注你需要哪些依賴庫(kù),對(duì)應(yīng)版本或者 Git 分支(需要提交到 Git)。
  • Cartfile.resolved:文件用來跟蹤項(xiàng)目當(dāng)前所用的依賴版本號(hào),為了保持多端開發(fā)一致(需要提交到 Git)。
  • Carthage:文件夾用來存放依賴庫(kù)的源文件和編譯后的文件(不需要提交到 Git,可以修改.gitignore文件,增加忽略 Carthage 文件夾就行了:#Carthage Carthage)。
備注:
Cartfile利用xcode-select命令來編譯Framework,如果你想用其他版的Xcode進(jìn)行編譯,執(zhí)行下面這條命令,把xcode-select的路徑改為另一版本Xcode就可以。
sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
9.引入Framework
  1. 設(shè)置Xcode自動(dòng)搜索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/庫(kù)名.framework"


以下是我安裝時(shí)出現(xiàn)的一些錯(cuò)誤。
錯(cuò)誤1:

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

錯(cuò)誤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

錯(cuò)誤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)
解決方案:
如果升級(jí)Carthage和brew都不行,可以升級(jí)下Xcode。

錯(cuò)誤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


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容