Carthage is similar to CocoaPods, either of them is all focus on manage dependencies in iOS/OS X develop environment. We prefer more use CocoaPods, which is very useful and convenience, also extensive be used in a lot of firm. I've been in research with a project use Carthage recently, I also got a lot of positive experience in this journey to push me record it.
Carthage will not create a workspace like CocoaPods, but also provide a kind of dependencies manage system. It uses a decentralization model to allow users addition frameworks and libraries what they need. It can be understood as only help you download and update third-party dependencies, don't care how to use your own.
Install Carthage:
We prefer use HomeBrew to install all kinds of tools in MAC environment.
$ brew install carthage
Carthage Usage:
-
Access the path of project.
$ cd path
-
Create a file named 'Carthage'
$ touch Cartfile
-
Edit the Cartfile file, Addition dependencies
github "Alamofire/AlamofireImage"
github "https://github.com/AFNetworking/AFNetworking"
-
Saving and close Cartfile file, execute install commend
$ carthage update --no-use-binaries --platform ios
After the installation, a folder named Carthage appears in the root path. It's include two folders that named 'Build' and 'Checkouts'
Under the path of 'Build/iOS' is target frameworks, we have to add the frameworks via Xcode by ourselves. However they are not download from Github directly.
The content of 'Checkouts' is the dateSource download via Github. The frameworks in 'Build/iOS' also build from here. Basically you can modify the function and structure, then execute 'Carthage build' commend thus output target framework by yourself.
Unfortunately they will be covered after you execute 'Carthage build' next time. So pay attention of the target folder that you don't want be covered by adding except.
-
Target -> Build Setting -> Search Paths -> Framework Search Path addition
$(PROJECT_DIR)/Carthage/Build/iOS
-
Target -> Build Phases -> '+' -> New Run Script Phase.
image.png
Add script/usr/local/bin/Carthage copy-frameworks
Add Input File$(SRCROOT)/Carthage/Build/iOS/AFNetworking.framework
-
Target -> General -> Linked Frameworks and Libraries -> add other ->Choose framework you need in 'Build/iOS ' path.
-
import framework at head of your class file.
image.png
That is specific introduction of usage. I'm going to introduce some issue when I use Carthage from next paragraph.
-
After we execute 'Carthage update', the terminal will print some issue at some times.
image.png
unable to find utility 'xcodebuild, not a developer tool or in PATH'
The reason why display like this is because in shell command could not find the 'xcodebuild' tool command in environment variables, the Carthage not able to use sourcecode build the dynamic framework in the meantime. We have to repoint the command line tools in Xcode preference.
image.png -
The last version of Carthage is 0.30.1 current time will fail to build facebookSDK. It has be mentioned in issue of Carthage Github.
https://github.com/Carthage/Carthage/pull/2507
We have two options:
First. reduce version of Carthage to 0.29.0.
Second. Delete the target of FBSDKIntegrationTests in facebookSDK. There are specific step introduction in above URL.
-
Network problem. Sometime we will wait for the checkout long time (approach 30min), which mean there are some network issue already occur. The terminal may will print some error code like below screenshot.
image.png
Fortunately, it's very easy to solve. We just need to delete the Carthage folder in root path, execute 'Carthage update' again.
All of there are what I discovery yet. I will keep investigate with other feature of Carthage in the future.
中文版:https://www.jianshu.com/p/7a0634e14332
欢迎加入Swift qq交流群:859978655
网友评论