问题
I ran carthage bootstrap --platform iOS
and got "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", and then at the end of the build I got a full on "Build Failed: Task failed with exit code 65" error.
It points me to the derivedDataPath
, and I checked the xcodebuild log for more details where it let me know "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)".
But I'm still not totally sure what exactly is happening with Realm Cocoa, or how to fix, do you know?
回答1:
TL;DR: Ensure you're using the latest Swift version, included with Xcode, and then perform carthage bootstrap --no-use-binaries --platform iOS --cache-builds
Long version:
The error you got from Xcode while building your project, Incompatible Swift version - framework was built with 3.1 and the local version is 4.0
, is due to a download performed by Carthage to get a pre-built version of Realm Framework (this is a time-saver feature but sometimes there are version incompatibilities like this one).
This downloaded pre-built framework was compiled with a previous version of Swift (in this case the error is pointing v3.1 was used.) The solution for this error will be to perform the dependencies installation process using a different command:
carthage bootstrap --platform iOS --no-use-binaries
This will work for the project dependencies build to succeed. Anyway this might take a long time since it will build from scratch the Realm.framework and RealmSwift.framework from the core every time the command is executed. So it is possible to enable a local cache for the builds on Carthage. The dependencies can be installed with
carthage bootstrap --no-use-binaries --platform iOS --cache-builds
With this options Carthage will:
- bootstrap, so the versions in the
Cartfile.resolved
will be used, no updates. --no-use-binaries
build the dependencies with no downloads of pre-built frameworks (avoiding the version incompatibility.)--platform iOS
will build the dependencies for be used only on iOS, avoiding building frameworks for Apple TV or Mac OS in case the dependency supports it. This will cut a lot of time!--cache-builds
will enable Carthage to store your built dependencies (and use it when re-needed) on a local cache, so even if you perform the command again it will just copy your stored framework, avoiding another time consuming build process.
回答2:
Check your application folder and Switch your Xcode version to older version with swift 3.
sudo xcode-select --switch /Applications/Xcode.app
来源:https://stackoverflow.com/questions/46835129/carthage-build-failed