升级了XCode 8.3.3,其支持Swift 3.1后,去编译项目结果出错:
/Users/crifan/dev/dev_root/daryun/Projects/上汽大众/斯柯达/卓越一线/sourcecode/SalesAppiOS/SalesApp/SelectRegionViewController.swift:964:8: Module compiled with Swift 3.0 cannot be imported in Swift 3.1: /Users/crifan/dev/dev_root/daryun/Projects/上汽大众/斯柯达/卓越一线/sourcecode/SalesAppiOS/Carthage/Build/iOS/RealmSwift.framework/Modules/RealmSwift.swiftmodule/x86_64.swiftmodule |
其中此处的RealmSwift是用Carthage去管理的:
➜ SalesAppiOS git:(master) ✗ cat Cartfile github "realm/realm-cocoa" == 2.0.0 |
之前刚刚去update过:
➜ SalesAppiOS git:(master) ✗ carthage update –platform iOS *** Cloning realm-cocoa *** Downloading realm-cocoa.framework binary at “v2.0.0" |
待会去试试:
carthage update –no-use-binaries –platform iOS
realm/realm-cocoa: Realm is a mobile database: a replacement for Core Data & SQLite
最新版本已经是3.0.0了,
Module compiled with Swift 3.0.2 cannot be imported in Swift 3.1 · Issue #4787 · realm/realm-cocoa
“update Carthage to 0.20.”
然后再去用carthage更新新版本的realm:
➜ SalesAppiOS git:(master) ✗ carthage update –platform iOS realm No entry found for dependency realm in Cartfile. ➜ SalesAppiOS git:(master) ✗ pwd /Users/crifan/dev/dev_root/daryun/Projects/上汽大众/斯柯达/卓越一线/sourcecode/SalesAppiOS ➜ SalesAppiOS git:(master) ✗ ll total 46496 drwxr-xr-x 4 crifan staff 136B 8 31 10:04 Bugly.framework -rw-r–r– 1 crifan staff 578B 8 31 10:19 Cartfile -rw-r–r–@ 1 crifan staff 626B 8 31 11:30 Cartfile.resolved drwxr-xr-x 4 crifan staff 136B 8 31 11:31 Carthage -rwxr-xr-x 1 crifan staff 11K 8 31 10:04 JPUSHService.h drwxr-xr-x 5 crifan staff 170B 8 31 10:04 PgySDK.framework -rw-r–r– 1 crifan staff 14B 8 31 10:04 README.md drwxr-xr-x 188 crifan staff 6.2K 8 31 10:04 SalesApp drwxr-xr-x@ 5 crifan staff 170B 8 31 10:07 SalesApp.xcodeproj drwxr-xr-x 9 crifan staff 306B 8 31 10:04 SalesAppDev -rw-r–r– 1 crifan staff 2.0K 8 31 10:04 SalesAppDev.plist drwxr-xr-x 4 crifan staff 136B 8 31 10:04 SalesAppDevTests drwxr-xr-x 4 crifan staff 136B 8 31 10:04 SalesAppDevUITests drwxr-xr-x 4 crifan staff 136B 8 31 10:04 SalesAppTests drwxr-xr-x 4 crifan staff 136B 8 31 10:04 SalesAppUITests -rw-r–r– 1 crifan staff 5.6K 8 31 10:04 TalkingData.h -rw-r–r– 1 crifan staff 11M 8 31 10:04 jpush-ios-2.1.8.a -rw-r–r– 1 crifan staff 11M 8 31 10:04 libTalkingData.a ➜ SalesAppiOS git:(master) ✗ carthage update –platform iOS realm/realm-cocoa No entry found for dependency realm/realm-cocoa in Cartfile. ➜ SalesAppiOS git:(master) ✗ carthage update –platform iOS realm-cocoa *** Fetching Cartography |
Carthage还是有些缺点的,包括:
此处制定了只更新realm-cocoa这个库,但是Carthage却去fetch别的库。。。
结果超时了:
➜ SalesAppiOS git:(master) ✗ carthage update –platform iOS realm-cocoa *** Fetching Cartography A shell task (/usr/bin/env git fetch –prune –quiet https://github.com/robb/Cartography.git refs/tags/*:refs/tags/* +refs/heads/*:refs/heads/* (launched in /Users/crifan/Library/Caches/org.carthage.CarthageKit/dependencies/Cartography)) failed with exit code 128: fatal: unable to access ‘https://github.com/robb/Cartography.git/’: Operation timed out after 300015 milliseconds with 0 out of 0 bytes received |
再去换个WI-FI网络试试,注,此处是开了shadowsock翻墙的。
➜ SalesAppiOS git:(master) ✗ carthage update realm-cocoa –platform iOS *** 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 A shell task (/usr/bin/env git fetch –prune –quiet https://github.com/danielgindi/Charts.git refs/tags/*:refs/tags/* +refs/heads/*:refs/heads/* (launched in /Users/crifan/Library/Caches/org.carthage.CarthageKit/dependencies/Charts)) failed with exit code 128: fatal: unable to access ‘https://github.com/danielgindi/Charts.git/’: Operation timed out after 300004 milliseconds with 0 out of 0 bytes received |
再去试试,好像是可以了:
➜ SalesAppiOS git:(master) ✗ carthage update realm-cocoa –platform iOS *** 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 *** Downloading realm-cocoa.framework binary at "v2.0.0" *** Skipped installing realm-cocoa.framework binary due to the error: "Incompatible Swift version – framework was built with swiftlang-800.0.46.2 clang-800.0.38 and the local version is swiftlang-802.0.53 clang-802.0.42." *** Checking out realm-cocoa at "v2.0.0" |
看到是,先去下载了网站上已编译好的二进制文件:realm-cocoa.framework
但是发现由于swift版本不一致:
网站编译用的是:swiftlang-800.0.46.2 -》 swift 3.0
自己本地的是:swiftlang-802.0.53 clang-802.0.42 -》 swift 3.1
所以carthage又去自动下载源码,用本地的swift 3.1去编译
但是一直卡死了,算了,断了,再去试试。
又去试了一遍,还是卡死在:
*** Checking out realm-cocoa at “v2.0.0"
想办法看看能不能先:
手动下载代码,然后手动从代码中编译:
记得貌似是
先checkout再build?
➜ SalesAppiOS git:(master) ✗ carthage help Available commands: archive Archives built frameworks into a zip that Carthage can use bootstrap Check out and build the project’s dependencies build Build the project’s dependencies checkout Check out the project’s dependencies copy-frameworks In a Run Script build phase, copies each framework specified by a SCRIPT_INPUT_FILE environment variable into the built app bundle fetch Clones or fetches a Git repository ahead of time help Display general or command-specific help outdated Check for compatible updates to the project’s dependencies update Update and rebuild the project’s dependencies version Display the current version of Carthage |
结果:
➜ SalesAppiOS git:(master) ✗ carthage fetch realm-cocoa *** Fetching realm-cocoa A shell task (/usr/bin/env git fetch –prune –quiet realm-cocoa refs/tags/*:refs/tags/* +refs/heads/*:refs/heads/* (launched in /Users/crifan/Library/Caches/org.carthage.CarthageKit/dependencies/realm-cocoa)) failed with exit code 128: fatal: ‘realm-cocoa’ does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. |
估计是要完整地址?
carthage fetch 用法
结果没有找到
carthage fetch fatal: ‘realm-cocoa’ does not appear to be a git repository
carthage fetch fatal does not appear to be a git repository
Carthage will not checkout Realm 2.8.x · Issue #5131 · realm/realm-cocoa
Cartfile that references current repository · Issue #965 · Carthage/Carthage
A shell task failed with exit code 128 (Carthage 0.8) · Issue #694 · Carthage/Carthage
加上–verbose试试:
carthage update realm-cocoa –platform iOS —verbose |
结果输出的内容, 和之前一样的层度,并没有更加verbose。
实在不行,就去试试:
不制定版本了:
github "realm/realm-cocoa" == 2.0.0
改为:
github "realm/realm-cocoa”
再去试试:
结果速度还是很慢。
重启iTerm试试,
carthage update realm-cocoa –platform iOS —verbose
然后就可以了:
➜ SalesAppiOS git:(master) ✗ carthage update realm-cocoa –platform iOS –verbose *** 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 *** Downloading realm-cocoa.framework binary at "v2.10.0" |
可以看到,其只是下载了最新版的二进制文件:v2.10.0的 realm-cocoa.framework
看来其是和当前的swift 3.1是兼容的
-》否则就应该会去下载源码并编译了。
然后再去Clean项目后,重新build编译,就可以解决此问题,正常继续编译了:
【总结】
此处,之前的Cartfile中由于指定了:
github "realm/realm-cocoa" == 2.0.0
导致对于旧版本v0.16.2的Carthage去update更新realm-cocoa的时候,只是下载下来了,用其他swift 3.0编译的realm-cocoa.framework,导致当前是swift 3.1的Xcode 8.3.3中无法正常编译,而报错:
Module compiled with Swift 3.0 cannot be imported in Swift 3.1
解决办法:
本来应该是,即使不该动配置:
github "realm/realm-cocoa" == 2.0.0
然后在升级了Carthage为0.20.0后,再去update更新realm-cocoa,也可以自动检测出下载下来的realm-cocoa.framework是和当前swift 3.1不兼容,所以会去重新checkout下载realm-cocoa的源码,然后再去build编译出所需要的realm-cocoa.framework。
但是此处不知道是网络问题还是其他什么原因,始终卡在checkout这一步:
*** Checking out realm-cocoa at “v2.0.0”
所以最后放弃这个办法。
改为:
Cartfile中不制定realm-cocoa的版本:
github "realm/realm-cocoa"
然后再去:
carthage update realm-cocoa –platform iOS
即可更新,下载到和swift 3.1兼容的v2.10.0的 realm-cocoa.framework,然后Xcode就可以正常使用,继续编译了。
转载请注明:在路上 » 【已解决】升级Xcode 8.3.3后编译项目出错:Module compiled with Swift 3.0 cannot be imported in Swift 3.1