美文网首页
Usage & Attention of Carthag

Usage & Attention of Carthag

作者: YJ_Wong | 来源:发表于2018-09-06 01:19 被阅读202次

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:

  1. Access the path of project.
    $ cd path

  2. Create a file named 'Carthage'
    $ touch Cartfile

  3. Edit the Cartfile file, Addition dependencies
    github "Alamofire/AlamofireImage"
    github "https://github.com/AFNetworking/AFNetworking"

  4. Saving and close Cartfile file, execute install commend
    $ carthage update --no-use-binaries --platform ios

image.png

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.

  1. Target -> Build Setting -> Search Paths -> Framework Search Path addition
    $(PROJECT_DIR)/Carthage/Build/iOS

  2. Target -> Build Phases -> '+' -> New Run Script Phase.
    Add script /usr/local/bin/Carthage copy-frameworks
    Add Input File $(SRCROOT)/Carthage/Build/iOS/AFNetworking.framework

    image.png
  3. Target -> General -> Linked Frameworks and Libraries -> add other ->Choose framework you need in 'Build/iOS ' path.

  4. 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.

  1. After we execute 'Carthage update', the terminal will print some issue at some times.
    unable to find utility 'xcodebuild, not a developer tool or in PATH'

    image.png
    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
  2. 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.

  1. 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

相关文章

网友评论

      本文标题:Usage & Attention of Carthag

      本文链接:https://www.haomeiwen.com/subject/lpjzwftx.html