Module compiled with swift 3.0 cannot be imported in Swift 3.0.1
Asked Answered
W

9

87

I upgraded Xcode to 8.1 GM and am now getting the below error for SwiftyJSON. Other imported frameworks seem to work. Is there a way to force this to work in Swift 3 until SwiftyJSON upgrades their framework? I used Carthage to import/update frameworks. I also tried changing Use Legacy Swift language version On and Off to no avail.

Module compiled with Swift 3.0 cannot be imported in Swift 3.0.1: Modules/SwiftyJSON.swiftmodule/arm64.swiftmodule

Wrack answered 25/10, 2016 at 21:54 Comment(0)
P
171

SwiftyJson is being downloaded precompiled by carthage. The precompiled download is with Swift Version 3.0. That makes the compiler complain that the version is not correct. Using the following command:

carthage update --platform iOS --no-use-binaries

SwiftyJson (and all other frameworks within Carthage) will be compiled locally using the local version of Swift (3.0.1) and the compiler will not complain anymore.

Parent answered 31/10, 2016 at 9:33 Comment(7)
You are welcome. To be honest carthage should be a bit more intelligent and check swift version number.Parent
Any other ideas? Because this did not worked for me, although in my case I am having problems with UnboxEntrepreneur
This was excellent. Is there a way to embed this in the Cartfile so that I can just type carthage update without fellow developers needing to know/worry about the extra flags?Septet
I think that you cannot embed it. You can probably add it to fastlane, but i have not tried.Parent
I had similar error with PromiseKit 4.0 after updating from to XCode 8.0 to XCode 8.1 I was having an EXC_BAD_ACCESS error. In the end, PromiseKit had to be recompiled with swift 3.0.1 and problem was solved.Hofstetter
Excuse me but where should I type this command Line ? From Terminal inside the Xcode folder ? I got a 'bash: carthage: command not found' @ParentHyracoid
@Hyracoid first install carthage brew install carthage , if it gives command not found install brewEarlearla
N
21

Remove the app chache from DerivedData, and rebuild. the error may be fixed.

The DerivedData path like this:

~/Library/Developer/Xcode/DerivedData/
Nugget answered 7/11, 2016 at 10:16 Comment(3)
Worked for me, I remove this folter, remove pod folder and use "pod install". And fixed.Juarez
Hi. This solution worked for me. Can you explain in detail what happens when we clear derived data? How the error goes away?Stradivarius
Worked for me too, Thanks.Proletarian
L
10

Make sure you've placed the new XCode 8.1 GM package in your Applications folder. We ran into this issue when one of us was running Carthage to update our dependencies, but had not replaced the XCode old 8.0 application in the applications folder (8.1 GM was running off the Desktop).

You want to make sure that when you run the following in terminal: xcrun swift -version that it returns Apple Swift version 3.0.1.

Lyford answered 26/10, 2016 at 4:45 Comment(8)
This worked for me, thank you! Also the command that worked in terminal was xcrun swift -versionWrack
Still getting the same issue. Any other suggestionsKleon
Correction, I am as well. Built it fine the first go around and now getting the error again when trying to run it.Wrack
This command worked for me: carthage update --platform iOS --no-use-binariesWrack
@Wrack - Thanks a bunch - that worked for me as well as it prevents the use of pre-built binaries that may have been compiled with a previous version of Swift.Piero
I've done carthage update --platform iOS --no-use-binaries and it still doesn't work. I've cleaned my project and restarted Xcode and I still get the error. Anything else I can try?Englebert
@CliftonLabrum What happens when you run xcrun swift -version in terminal from your project directory.Lyford
I tried that. It returns Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1) Target: x86_64-apple-macosx10.9Englebert
F
9

Updating default Xcode to new one on terminal worked for me.

Step 1 : Use following command to update Xcode version to latest on Terminal. Ref

sudo xcode-select -switch <path/to/>Xcode.app

Step 2 : Now try carthage update command

carthage update --platform iOS
Flurried answered 21/12, 2016 at 11:25 Comment(0)
D
9

Just to give the latest updates:

Carthage has released version 0.20 on Feb 27, 2017.

Carthage now only uses the pre-build binary if available pre-build binary is compatible.

That is being said, you no longer have to use: --no-use-binaries to avoid incompatible pre-build framework.

So make sure that you have carthage version greater than 0.20 and simply do:

carthage update --platform iOS
Diapason answered 28/3, 2017 at 21:12 Comment(2)
XCode 8.3.3 After updating Carthage to 0.25 version and after doing below, it worked for me carthage update --platform iOS --no-use-binariesHesperus
@Hesperus It does not work for you without --no-use-binaries? Carthage should be able to detect if the binary is compatible with your compiler version. If not compatible, it's supposed to automatically drop the downloaded binary and build the framework locally.Diapason
S
5

Just like @zirinisp said:

  1. You can Using the following command:carthage update --platform iOS --no-use-binaries
  2. Using the following command:xcrun swift -version to see the Swift version
  3. Do this: Xcode->preferences->locations to clear the derived data and archives data, the most important to change the command line tools to "Xcode 8.1"
  4. Using the following command:xcrun swift -version,you can see the swift version is 3.0.1
  5. Set Use Legacy Swift Language Version = NO

I hope it will help you

Sanskrit answered 22/11, 2016 at 7:0 Comment(0)
N
1
  1. Move the beta/GM version if the Xcode to /Applications folder and name it Xcode-beta

  2. Check the output of:

    xcrun swift --version

by running this command in terminal, its output should match with the swift version you want the app to compile, because Carthage uses output of this command, to determine the local Swift version.

  1. Update Xcode version to latest on Terminal by running following command:

    sudo xcode-select -s /Applications/Xcode-beta.app/

  2. Build the libraries for iOS and prevents Carthage from downloading existing (yet incompatible) precompiled binaries, by running following command:

    carthage update --platform iOS --no-use-binaries

  3. Clean & Build

Namaqualand answered 6/8, 2018 at 13:31 Comment(0)
N
0

I had exactly the same issue with the library XCTest_Gherkin, what it worked for me was:

  1. Product -> Scheme -> XCTest-Gherkin
  2. Product -> Build

Hope it helps. I am using Cocoapods.

Nourish answered 16/11, 2016 at 7:43 Comment(0)
O
0

In Xcode Build Settings make sure your Framework Search Paths contain the appropriate Carthage Build folder:

$(inherited)
$(PROJECT_DIR)/Carthage/Build/iOS
Outnumber answered 18/4, 2017 at 17:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.