Xcode 9 : Module compiled with Swift 3.1 cannot be

2019-01-30 07:50发布

问题:

After updating to Xcode 9, I tried to build one of my projects.

I use the FacebookLogin pod. I have a compiler error in FacebookLogin/LoginButton.swift

@testable import FacebookCore
❌ Module compiled with Swift 3.1 cannot be imported in Swift 4.0

In my target's build settings, the Swift language version is set to Swift 3.2.

I guess I need to wait for Facebook to update their pod ? Or any other suggestion ?

Thanks !

回答1:

Update:

Solution also tested and working in Swift 4.2 and Xcode 10.

Original:

I would like to add that if you are using Carthage to compile a module in Swift 3.2 you should go to a terminal and run:

sudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer

To use the Xcode 9 command line tools, then you can run:

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

This will compile the library with your current command line tools, it can be a bit slow but now the project should build.

Note

To revert and use your stable Xcode command line tools simply run:

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


回答2:

Xcode 9 comes with a Swift 4 compiler that understands both Swift 3.2 and swift 4, it even lets you mix and match between the 2 versions. Unfortunately, other versions aren't supported.

Even if you set your language to Swift 3.2, it uses the Swift 4 compiler.

If you're using cocoapods, you can add this to the end of your pod file to force the pods to use Swift 3.2 or 4.0:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '3.2'
        end
    end
end

Alternatively, you could put the files from the pod directly into your project temporarily, until FacebookLogin is updated to Swift 3.2 or 4.

Note: Edited based on Matt's feedback



回答3:

Maybe you can clean the target before you build it. It works fine for me.



回答4:

I ran into the same issue on Xcode 9 Beta 3, which pointing to 'Alamofire' and tried a few different solutions, the easiest one i found is

1. CMD+SHIFT+K to clean the build
2. Restart Xcode 9 <-- make sure you do this step, that's critical. `


回答5:

Doing a "clean build folder" and restarting Xcode 9 cleaned up the error for me. Also the error didn't stop the app from running on my device or the simulator.



回答6:

goto xcode DerivedData directory then remove all file inside it and recompile your project . it work for me .

and default DerivedData directory is :~/Library/Developer/Xcode/DerivedData.



回答7:

If using Carthage , Open terminal and;

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

If using Pod , Open terminal and;

pod update

(Also if don't work in pod, you can change SWIFT_VERSION in podfile Ex:

config.build_settings['SWIFT_VERSION'] = '3.2'

)

After;

Open Xcode and use;

Command+Option+Shift+K



回答8:

It works for me.

1.Clean your project in Xcode 8

2.Build or run your project in Xcode 9



回答9:

I cleaned the project in Xcode 9, and then run the app, it works.



回答10:

I had the same problem with Xcode 9 GM and this solved my problem: Remove it from the project and drag it again into "Embedded Binaries".



回答11:

Clean Build Folder

Cmd + option + shift + K


回答12:

I have

pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'

in my project and import FBSDKLoginKit, after cleaning the target i didn't have any issue

Since the pod you are using is in swift and is a beta pod, it is likely that you would have some issues with the swift 4 compiler, you should use the objective-c version of the pod for the time being



回答13:

If you use from Pod:

  1. In Podfile comment FacebookLogin pod
  2. pod install

  3. In Podfile uncomment FacebookLogin pod
  4. pod install

  5. Run again your project


回答14:

For my case - the actual pod referenced a static zip with prebuilt binaries targeting swift 3.1. So only solution is to rebuild the framework with source from xcode 9.

https://github.com/AudioKit/AudioKit/issues/980