最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Xcode9中报错:Module compiled with Swift 3.1 cannot be imported in Swift 3.2

Xcode crifan 3896浏览 0评论

折腾:

【部分解决】通过下载和安装使用Xcode9避免Xcode8索引和编译极其慢的问题

期间,去:

import Cartography

出错:

/Users/crifan/dev/dev_root/xxxxxx/SRT/ShopVisitHeadView.swift:10:8: Module compiled with Swift 3.1 cannot be imported in Swift 3.2: /Users/crifan/dev/dev_root/xxxxxx/Carthage/Build/iOS/Cartography.framework/Modules/Cartography.swiftmodule/x86_64.swiftmodule

Module compiled with Swift 3.1 cannot be imported in Swift 3.2

ios – Xcode 9 : Module compiled with Swift 3.1 cannot be imported in Swift 4.0 – Stack Overflow

去更新库:

carthage update Cartography --platform iOS --no-use-binaries
➜  SRT git:(master) ✗ carthage update Cartography --platform iOS --no-use-binaries
Please update to the latest Carthage version: 0.25.0. You currently are on 0.24.0
*** Fetching Cartography
*** Fetching MGSwipeTableCell
*** Fetching Alamofire
*** Fetching TextFieldEffects
*** Fetching SwiftyJSON
*** Fetching KMPlaceholderTextView
*** Fetching realm-cocoa
*** Fetching SwiftHEXColors
*** Fetching SwiftHTTPStatusCodes
*** Fetching ActionSheetPicker-3.0
*** Fetching Kingfisher
*** Fetching Charts
*** Fetching SwiftKeychainWrapper
*** Fetching DLRadioButton
*** Fetching XCGLogger
*** Checking out Cartography at "1.1.0"
*** xcodebuild output can be found in /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/carthage-xcodebuild.lg2UBj.log
*** Building scheme "Cartography-iOS" in Cartography.xcworkspace

然后clean项目,再去编译看看结果

结果问题依旧

去看了看库Cartography.framework,是刚刚重新编译出来的啊:

退出Xcode9重新打开,结果问题依旧。

ios – Module compiled with swift 4.0 cannot be imported in swift 3.1 – Stack Overflow

先去:

➜  SRT git:(master) ✗ ls ~/Library/Caches/org.carthage.CarthageKit/DerivedData

Cartography

➜  SRT git:(master) ✗ rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData

再去:

carthage update --platform iOS --no-use-binaries
➜  SRT git:(master) ✗ carthage update --platform iOS --no-use-binaries
Please update to the latest Carthage version: 0.25.0. You currently are on 0.24.0
*** Fetching Cartography
*** Fetching MGSwipeTableCell
*** Fetching Alamofire
*** Fetching TextFieldEffects
*** Fetching SwiftyJSON
*** Fetching KMPlaceholderTextView
*** Fetching realm-cocoa
*** Fetching SwiftHEXColors
*** Fetching SwiftHTTPStatusCodes
*** Fetching ActionSheetPicker-3.0
*** Fetching Kingfisher
*** Fetching Charts
*** Fetching SwiftKeychainWrapper
*** Fetching DLRadioButton
*** Fetching XCGLogger
*** Checking out DLRadioButton at "1.4.9"
*** Checking out Charts at "v3.0.3"
*** Checking out Cartography at "1.1.0"
*** Checking out SwiftKeychainWrapper at "2.2.1"
*** Checking out Kingfisher at "3.13.1"
*** Checking out SwiftHTTPStatusCodes at "3.1.2"
*** Checking out ActionSheetPicker-3.0 at "2.2.0"
*** Checking out SwiftHEXColors at "1.1.1"
*** Checking out realm-cocoa at "v2.0.0"
*** Checking out KMPlaceholderTextView at "1.3.0"
*** Checking out SwiftyJSON at "3.1.4"
*** Checking out TextFieldEffects at "1.3.3"
*** Checking out Alamofire at "4.5.1"
*** Checking out MGSwipeTableCell at "1.6.1"
*** Checking out XCGLogger at "Version_4.0.0"
*** xcodebuild output can be found in /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/carthage-xcodebuild.CcXf3b.log
*** Building scheme "CoreActionSheetPicker" in ActionSheetPicker-3.0.xcworkspace
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
*** Building scheme "Cartography-iOS" in Cartography.xcworkspace
*** Building scheme "Charts" in Charts.xcodeproj

RealmSwift Module compiled with Swift 3.1 cannot be imported in Swift 3.2 in iOS 11 beta 5 · Issue #5229 · realm/realm-cocoa

也是推荐:

  • Delete cartfile.resolved and carthage folders
  • Do carthage update by using the command – carthage update –platform iOS –no-use-binaries

此处,也注意到,Target的Build Setting中Swift Language Version设置的是:Unspecified

而从Xcode9编译出错提示可以看出,此处虽然没有指定swift版本,默认用了swift 3.2

Module compiled with Swift 3.0.1 cannot be imported in Swift 3.1: · Issue #1878 · Carthage/Carthage

Module compiled with Swift 3.1 cannot be import… | Apple Developer Forums

Module compiled with Swift 3.1 cannot be imported in Swift 4.0 · Issue #640 · watson-developer-cloud/swift-sdk

另外,去看了看本地的command line的设置,默认已经用9了:

Command Line Tools:Xcode 9.0(9A235)

结果期间又出错了:

【已解决】Xcode9中Carthage编译Realm出错:Build Failed Task failed with exit code 65

然后再去看看Xcode是否还会报错。

然后就正常了:

【总结】

此处先去清理Carthage的之前的缓存:

rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData

再去:

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

即可,然后所有的第三方库的,不使用预先编译好的库,而是下载源码,用Xcode9的编译器(此处默认的Swift 3.2)去重新编译,即可生成Xcode9中可以正常使用的库了。

转载请注明:在路上 » 【已解决】Xcode9中报错:Module compiled with Swift 3.1 cannot be imported in Swift 3.2

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
99 queries in 0.185 seconds, using 23.33MB memory