Quickest way to add Carthage in Xcode Project

折月煮酒 提交于 2020-04-29 19:24:04

问题


What is quickest way to add dependencies in Xcode project using Carthage.

How to add or edit dependencies later.


回答1:


Install Carthage

Download Carthage

Open terminal

Terminal: cd ~/Path/To/Folder Containing Project

Create Carthage file as:

Terminal: touch Cartfile

Open Cartfile file from project folder and add required dependency

Example Cartfile file

github "Alamofire/Alamofire" == 4.5

github "Alamofire/AlamofireImage"

After Editing Cartfile file save it.

Run following command from terminal

Terminal: carthage update --platform iOS

xCode > Build phases

  • Plus button on top left > New Run Script Phases
  • Run Script > Shell script window > add following:

/usr/local/bin/carthage copy-frameworks

  • Run Script > Input file window > add following:

$(SRCROOT)/Carthage/Build/iOS/DependencyName.framework

  • Link Binary With Libraries > Plus button > Add Other > Navigate to Project Folder > Carthage > Build > iOS > Framework to add

Done




回答2:


  1. Installing Carthage

    //Homebrew
    brew install carthage
    
  2. Create Cartfile file at the project(.xcodeproj)/workspace(.xcworkspace) directory

  3. Modify Cartfile. Add necessary dependency == repo

    github "<owner>/<repo>" == <version>
    

    [Note] Any carthage command should be called from Cartfile folder

  4. Run carthage update. High level logic:

    `carthage update [dependency]` {
        - reads `Cartfile`, resolves dependency graph and generates `Cartfile.resolved` to store a list of versions that will be actually built
    
        //--no-use-binaries - this flag force a Carthage to not use a `Prebuilt framework`
        //--no-build - this flag skip a building step - `carthage build`
    
        `carthage bootstrap [dependency]` {
            - reads `Cartfile.resolved`
            `carthage checkout [dependency]` {
                `carthage fetch <path>` {
                    - fetch dependency from `Cartfile.resolved` into `~/Library/Caches/org.carthage.CarthageKit/` folder
                }
                - checkout/move a dependency from `~/Library/Caches/org.carthage.CarthageKit/` to generated `Carthage/Checkouts` folder
            }
            `carthage build [dependency]` {                
                - builds all `shared frameworks schemes` from `Carthage/Checkouts` into generated `Carthage/Build` folder
    
                //--no-skip-current - this flag also builds all `shared frameworks schemes` of a consumer workspace/project(in addition to `Carthage/Checkouts` folder)
            }
        }
    }   
    
  5. Drag and drop builded frameworks to General -> Frameworks and Libraries

  6. Run the next script. This step is important because carthage build process a fat binary(arm64... + x86_64) using lipo[About]. Apple reject application which uses it. That is why you should add this extra step to cut architecture for simulator(x86_64)

    Build Phases -> + -> New Run Script phase -> 
    
        // /usr/local/bin/carthage - path to Carthage, copy-frameworks - command which sets a necessary architecture and copies framework to an application bundle
        Shell -> /usr/local/bin/carthage copy-frameworks
    
        //path to a generated Carthage/Build
        Input files -> + -> $(SRCROOT)/Carthage/Build/<platform>/<name>.framework
    

[Fast Carthage build]

[Vocabulary]

[CocoaPods vs Carthage]



来源:https://stackoverflow.com/questions/52714746/quickest-way-to-add-carthage-in-xcode-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!