美文网首页
Cartahge简单使用

Cartahge简单使用

作者: coming_168 | 来源:发表于2021-09-30 11:55 被阅读0次

Carthage也是一个比较好用的三方框架管理工具,原理是自动帮我们把工程编译为Dynamic framework(动态库),仅支持iOS8以上。相比Cocoa pods对项目更无侵入性,但是用习惯了cocoapods,Carthage就显得稍微麻烦一点了。

一、安装Carthage

使用Homebrew来安装Carthage,先安装Homebrew并升级
1⃣️Homebrew的安装:
可以根据Homebrew官网: https://brew.sh/index_zh-cn 进行安装;
也可以使用终端直接安装:

 /bin/bash-c"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2⃣️Homebrew的升级:

sudo brew update

3⃣️安装Carthage:

// 安装
sudo brew install carthage
// 查看版本
carthage version
// 升级
brew upgrade carthage
// 卸载
sudo brew uninstall carthage

二、使用Carthage下载三方框架

1、在工程文件里创建一个Cartfile文件:

cd到工程文件,然后执行如下命令

// 创见Cartfile文件
touch Cartfile
// 使用Xcode命令打开Cartfile文件
open -a Xcode Cartfile
2、在CArtfile文件添加依赖库
github "Alamofire/Alamofire" ~> 5. image.png
  • 版本的含义:如果没有指明版本号,则会自动使用最新的版本
    1⃣️~>5.0:表示使用版本5.0以上但是低于6.0的最新版本,如5.1,5.4
    2⃣️==5.0:表示使用5.0版本
    3⃣️>=5.0:表示使用5.0或更高的版本
3、保存并关闭Cartfile文件,然后执行安装
// 下载添加依赖库的第三方框架
carthage update
执行完之后,会在工程目录里生成一个Carthage的文件夹,里面有自动生成的framework image.png
  • 有时候Carthage 更新出现报错 arm64:
A shell task (/usr/bin/xcrun lipo -create /Users/coming_ay/Library/Caches/org.carthage.CarthageKit/DerivedData/12.5.1_12E507/Alamofire/5.4.4/Build/Intermediates.noindex/ArchiveIntermediates/Alamofire\ iOS/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Alamofire.framework/Alamofire /Users/coming_ay/Library/Caches/org.carthage.CarthageKit/DerivedData/12.5.1_12E507/Alamofire/5.4.4/Build/Products/Release-iphonesimulator/Alamofire.framework/Alamofire -output /Users/coming_ay/Desktop/AY_Project/123456/Carthage/Build/iOS/Alamofire.framework/Alamofire) failed with exit code 1:
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: /Users/coming_ay/Library/Caches/org.carthage.CarthageKit/DerivedData/12.5.1_12E507/Alamofire/5.4.4/Build/Intermediates.noindex/ArchiveIntermediates/Alamofire iOS/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Alamofire.framework/Alamofire and /Users/coming_ay/Library/Caches/org.carthage.CarthageKit/DerivedData/12.5.1_12E507/Alamofire/5.4.4/Build/Products/Release-iphonesimulator/Alamofire.framework/Alamofire have the same architectures (arm64) and can't be in the same fat output file

Building universal frameworks with common architectures is not possible. The device and simulator slices for "Alamofire" both build for: arm64
Rebuild with --use-xcframeworks to create an xcframework bundle instead.
  • 根据提示终端重新输入:
// 不区分iOS、macOS
carthage update --use-xcframeworks
// 只限iOS
carthage update --platform iOS --use-xcframeworks
  • 有时候需要我们手动将编译完的动态看framework复制到iOS文件中才行:找到重新编译的framework , 选择需要的真机/模拟器,然后手动复制到 build/iOS 中 image.png

三、将下载三方框架集成到项目

1. 设置Xcode自动搜索Framework的目录:
Target -> Build Setting -> Search Paths -> Frame Search Paths处,添加如下:$(PROJECT_DIR)/Carthage/Build/iOS image.png
2. 添加编译的脚本:
Target -> Build Phases -> 点击 + -> New Run Script Phase -> 添加脚本:/usr/local/bin/carthage copy-frameworks image.png
3.添加编译framework文件:
打开工程文件中的iOS文件夹 -> 将framework文件拖入到项目General中的Frameworks,Libraries中 image.png

或者:
在Target -> Build Phases -> Run Script -> Input Files处添加如下:
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework

编译成功就可以导入头文件使用了: image.png

相关文章

  • Cartahge简单使用

    Carthage也是一个比较好用的三方框架管理工具,原理是自动帮我们把工程编译为Dynamic framework...

  • Carthage入门

    前言 为了便于快速使用,遂记录下此章。如果想了解更多,更全面的Cartahge,可以跳转Carthage官方文档翻...

  • Module compiled with Swift 5.0 c

    XCode升级到11.3后,使用Carthage引用的第三方库报错 解决方法:确保所有第三方库cartahge u...

  • 简单使用

    创建模型 过滤器 我们有一些字段和我们想让用户筛选的基础上 名称、价格或release_date。 我们创建一个 ...

  • gorange

    数组中简单使用 map中简单使用

  • 简单使用使用kaggle

    向我这样的条件不好的可以考虑借助云gpu来加速训练,借助kaggle可以在kaggle服务器上训练数据,kaggl...

  • 零碎的小程序笔记

    目录 template的简单使用WXS的简单使用npm的简单使用倒计时js的实现wx:for的使用一些js方法记录...

  • 命令行的简单使用

    Git命令行的简单使用,仅供自己使用 pod命令行的简单使用

  • 单元测试和OCMock

    OCMock使用一、安装及简单使用:使用Cocoapod引入:pod 'OCMock' 简单使用:新建一个单元测试...

  • Alamofire类似AFNetworking的简单使用和封装

    简单的使用。简单的使用。简单的使用。注定该文弱鸡一个,求拍砖。 一、介绍 Alamofire(Swift)的前身是...

网友评论

      本文标题:Cartahge简单使用

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