迦太基构建失败

Carthage Build Failed

我 运行 carthage bootstrap --platform iOS 得到了 "Skipped installing realm-cocoa.framework binary due to the error: Incompatible Swift version - framework was built with 3.1 and the local version is 4.0",然后在构建结束时我得到了 "Build Failed: Task failed with exit code 65"错误。

它指向 derivedDataPath,我检查了 xcodebuild 日志以了解更多详细信息,它让我知道 "PhaseScriptExecution Download\ Core\ and\ Sync /Users/user/Libary/Caches/org.carthage.CarthageKit/DerivedData/9.0_9A###/realm-cocoa/v2.10.2/Build/Intermediates.noindex/Realm.build/Release-iphoneos/Realm.build/Script-X#X#X#X#X.sh (1 failure)".

但我仍然不完全确定 Realm Cocoa 到底发生了什么,或者如何修复,你知道吗?

TL;DR: 确保您使用的是最新的 Swift 版本,包含在 Xcode 中,然后执行 carthage bootstrap --no-use-binaries --platform iOS --cache-builds

长版:

您在构建项目 Incompatible Swift version - framework was built with 3.1 and the local version is 4.0 时从 Xcode 得到的错误是由于 Carthage 执行下载以获取 Realm Framework 的预构建版本(这是一个时间-保护程序功能,但有时会出现版本不兼容问题,例如这个)。

这个下载的预构建框架是用以前版本的Swift编译的(在这种情况下,错误指向使用了v3.1。)这个错误的解决方案是执行依赖项安装使用不同的命令处理:

carthage bootstrap --platform iOS --no-use-binaries

这将有助于项目依赖项构建成功。无论如何,这可能需要很长时间,因为每次执行命令时,它都会从核心重新构建 Realm.framework 和 RealmSwift.framework。因此可以为 Carthage 上的构建启用本地缓存。可以使用

安装依赖项

carthage bootstrap --no-use-binaries --platform iOS --cache-builds

有了这个选项,迦太基将:

  • bootstrap,因此将使用 Cartfile.resolved 中的版本,不会更新。
  • --no-use-binaries 在不下载预构建框架的情况下构建依赖项(避免版本不兼容。)
  • --platform iOS 将构建仅用于 iOS 的依赖项,避免为 Apple TV 或 Mac OS 构建框架,以防依赖项支持它。这会节省很多时间!
  • --cache-builds 将使 Carthage 能够在本地缓存中存储您构建的依赖项(并在需要时使用它),因此即使您再次执行该命令,它也只会复制您存储的框架,避免另一个耗时的构建过程。

检查您的应用程序文件夹并使用 swift 将您的 Xcode 版本切换到旧版本 3.

sudo xcode-select --switch /Applications/Xcode.app