【问题标题】:How to fix Carthage Build Error: "SWIFT_VERSION '3.0' is unsupported" when Swift 5 is selected如何修复 Carthage 构建错误:选择 Swift 5 时“不支持 SWIFT_VERSION '3.0'”
【发布时间】:2019-10-20 16:53:00
【问题描述】:

我正在将基于 Alamofire 的“NetworkFoundation”框架迁移到 Swift 5。Carthage 被用作依赖项管理器,

购物车文件如下所示:

github "Alamofire/Alamofire" "5.0.0-beta.5"

命令carthage update 执行成功。在 Xcode 中构建项目,但是当我在框架的根目录中运行命令 carthage build --no-skip-current 时,它失败了:

xcodebuild 输出可以在 /var/folders/1m/qjb4gks13d54rqmn9ptwjmmw0000gp/T/carthage-xcodebuild.bg5VCR.log 中找到

Alamofire.xcworkspace 中的构建方案“Alamofire macOS”

在 Alamofire.xcworkspace 中构建方案“Alamofire tvOS”

在 Alamofire.xcworkspace 中构建方案“Alamofire watchOS”

在 Alamofire.xcworkspace 中构建方案“Alamofire iOS”

在 MyNetworkFoundation.xcodeproj 中构建方案“MyNetworkFoundation”

在 Alamofire.xcworkspace 中构建方案“Alamofire iOS”

构建失败

任务失败,退出代码为 65:

/usr/bin/xcrun xcodebuild -workspace /Users/MyUser/Documents/Projects/MyNetworkFoundation/MyNetworkFoundation/Carthage/Checkouts/Alamofire/Alamofire.xcworkspace -scheme Alamofire\ iOS -configuration Release -sdk iphoneos ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED= NO CODE_SIGN_IDENTITY= CARTHAGE=YES archive -archivePath /var/folders/1m/qjb4gks13d54rqmn9ptwjmmw0000gp/T/MyNetworkFoundation SKIP_INSTALL=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=NO CLANG_ENABLE_CODE_COVERAGE=NO STRIP_INSTALLED_PRODUCT=NO(在 /Project/MyNetworkFoundation/MyUser/ 中启动)/ >

这通常表示项目本身编译失败。请查看 xcodebuild 日志以获取更多详细信息:/var/folders/1m/qjb4gks13d54rqmn9ptwjmmw0000gp/T/carthage-xcodebuild.bg5VCR.log

按照建议,我检查了失败构建的日志文件。里面写着:

error: SWIFT_VERSION '3.0' is unsupported, supported versions are: 4.0, 4.2, 5.0. (in target 'Alamofire iOS') ** ARCHIVE FAILED **

所以我检查了我的项目的 Swift 版本,这似乎是正确的。

因为日志文件指出目标“Alamofire iOS”中使用了 Swift 3.0 版,所以我检查了目标

/MyNetworkFoundation/Carthage/Checkouts/Alamofire/Alamofire.xcodeproj

但它们都有 Swift 版本 5。 我不知道当我想构建我的项目时为什么会出现这个错误。我什至尝试重新安装 Xcode,但也没有用。有人知道我错过了什么吗?

Xcode 版本:10.2.1 (10E1001) MacOS 版本:10.14.5 (18F132)

【问题讨论】:

  • 安装 Alamofire 的 pod 代码是什么?

标签: ios swift alamofire carthage swift5


【解决方案1】:

不确定这是否会为您解决问题,但我遇到了类似的情况。对我来说,因为我刚刚复制了一个我正在加入的项目的 repo,所以我正在运行 carthage bootstrap 并且对于像你这样的 Swift 3 错误的 Alamofire,它总是失败。

我的 Cartfile 文件有 github "Alamofire/Alamofire" ~> 4.7.2,我的项目使用的是 Swift 4.2(同样,与您的设置不完全相同)。

我终于让它运行以下命令:

carthage bootstrap --platform iOS --no-use-binaries --toolchain com.apple.dt.toolchain.Swift_4_2

我相信诀窍是指定工具链使用 Swift 4.2,所以我建议你尝试使用 Swift_5_0。希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2019-08-17
    • 2017-02-17
    • 2019-10-19
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 2016-04-19
    • 1970-01-01
    相关资源
    最近更新 更多