Carthage安装及使用

作者: 靠谱丶活好 | 来源:发表于2016-04-09 01:49 被阅读12609次
    1.使用Homebrew安装Carthage之前,先对其进行更新,不然可能会安装到比较老的版本。

    sudo brew update

    2.安装Carthage
    • 方法1
      sudo brew install carthage
    • 方法2
      下载安装Carthage.pkg
    • 方法3
      下载Carthage,运行make install。
    3.查看及升级Carthage版本
    • 查看:carthage version
    • 升级:brew upgrade carthage
    4.卸载Carthage

    sudo brew uninstall carthage

    5.创建空的Cartfile文件

    touch Cartfile

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

    open -a Xcode Cartfile

    7.添加依赖库

    例:github "Alamofire/Alamofire" ~> 3.0
    - 版本的含义:
    ~>3.0:表示使用版本3.0以上但是低于4.0的最新版本,如3.5, 3.9。
    ==3.0:表示使用3.0版本。
    >=3.0:表示使用3.0或更高的版本。
    如果你没有指明版本号,则会自动使用最新的版本。

    8.保存并关闭Cartfile文件并执行carthage update

    执行update命令后,你的项目目录结构大致如下:


    • Cartfile:文件用来标注你需要哪些依赖库,对应版本或者 Git 分支(需要提交到 Git)。
    • Cartfile.resolved:文件用来跟踪项目当前所用的依赖版本号,为了保持多端开发一致(需要提交到 Git)。
    • Carthage:文件夹用来存放依赖库的源文件和编译后的文件(不需要提交到 Git,可以修改.gitignore文件,增加忽略 Carthage 文件夹就行了:#Carthage Carthage)。
    备注:
    Cartfile利用xcode-select命令来编译Framework,如果你想用其他版的Xcode进行编译,执行下面这条命令,把xcode-select的路径改为另一版本Xcode就可以。
    sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
    
    9.引入Framework
      1. 设置Xcode自动搜索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/库名.framework"


    以下是我安装时出现的一些错误。
    错误1:

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

    错误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

    错误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)
    解决方案:
    如果升级Carthage和brew都不行,可以升级下Xcode。

    错误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


    相关文章

      网友评论

      • Monkey_hbh:使用carthage安装Charts 一直报错 Referenced from: /private/var/containers/Bundle/Application/EA5C3B19-914E-4E56-BCDD-1D0CA79F5972/TestTableViewSwip.app/Frameworks/Charts.framework/Charts
        Reason: image not found
        靠谱丶活好:在Embedded Binaries 中引入Charts.framework
      • dispatch_async:楼主辛苦,谢谢了
      • a7642f69975b:*** Skipped building MJRefresh due to the error:
        Dependency "MJRefresh" has no shared framework schemes for any of the platforms: iOS
        a7642f69975b:楼主,编译这个库不成功啊,需要我自己手动改工程后 从新update吗?
      • 十一岁的加重:不错,很详细
      • 07d93406ec39:你好。。我遇到這樣的問題:The following binaries use incompatible versions of Swift. 我用給的是 Xcode 8.0
        779b68e64744:@漩渦貓_Lanaya 你是怎么解决的呀
        07d93406ec39:@GainellMe 沒錯。。我解決了 哈哈
        779b68e64744:@漩渦貓_Lanaya 应该是你打的framework是早期版本的,和默认的swift3.0并不兼容。。。

      本文标题:Carthage安装及使用

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