Quickest way to add Carthage in Xcode Project

前端 未结 2 970
谎友^
谎友^ 2021-01-03 09:25

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

How to add or edit dependencies later.

相关标签:
2条回答
  • 2021-01-03 09:57

    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

    0 讨论(0)
  • 2021-01-03 10:00
    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>
      
    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
      

    *Any carthage command should be called from Cartfile folder

    [Fast Carthage build]

    [Vocabulary]

    [CocoaPods vs Carthage]

    0 讨论(0)
提交回复
热议问题