ios Xcode 8 beta 4:构建失败并显示“以下二进制文件使用不兼容的 Swift 版本:”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38793192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:51:57  来源:igfitidea点击:

Xcode 8 beta 4: Build fails with "The following binaries use incompatible versions of Swift:" error

iosiphonexcodeswift3xcode8

提问by iGA

With new Xcode 8 beta 4we started experiencing the following error during CopySwiftLibsbuild phase:

使用 newXcode 8 beta 4我们在CopySwiftLibs构建阶段开始遇到以下错误:

Effective srcDirs: {(

    <DVTFilePath:0x7f865961e970:'/Volumes/Data/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator'>,

    <DVTFilePath:0x7f8657d02b20:'/Volumes/Data/Xcode-beta.app/Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/lib/swift/iphonesimulator'>

)}

error: The following binaries use incompatible versions of Swift:

错误:以下二进制文件使用了不兼容的 Swift 版本:

/Users/user/Projects/git/iphone-swift-1/DerivedData/myApp/Build/Products/Debug-iphonesimulator/myApp.app/myApp

/Users/user/Projects/git/iphone-swift-1/myApp/myAppApi.framework/myAppApi

/Users/user/Projects/git/iphone-swift-1/DerivedData/myApp/Build/Products/Debug-iphonesimulator/myApp.app/myApp

/Users/user/Projects/git/iphone-swift-1/myApp/myAppApi.framework/myAppApi

myAppApi is a subproject in the workspace that contains some shared code (it uses Alamofire).

myAppApi 是工作区中的一个子项目,其中包含一些共享代码(它使用Alamofire)。

One thing to note: originally we converted project from Swift 2.2 to Swift 2.3, and then manually upgraded to 3.0.

需要注意的一点:最初我们将项目从 Swift 2.2 转换为 Swift 2.3,然后手动升级到 3.0。

Does anyone have any idea what might be causing this error?

有谁知道可能导致此错误的原因?

Thanks!

谢谢!

回答by ossmalpha

I had the same problem, but managed to fixit by:

我有同样的问题,但设法通过以下方式解决它:

  1. Clean the project.
  2. Close project and quit Xcode.
  3. Clean derived data.
  4. Open the project again and it's there, all nice and working.
  1. 清理项目。
  2. 关闭项目并退出 Xcode。
  3. 清理派生数据。
  4. 再次打开项目,它就在那里,一切都很好,而且工作正常。

I did this on Xcode 8 using Swift 3.

我使用 Swift 3 在 Xcode 8 上做了这个。

回答by iAmcR

You can also get this problem, if you have the scenario of your container app's code is Swift 2.3 and you're creating a new extension in Xcode 8.

如果您的容器应用程序的代码是 Swift 2.3 并且您正在 Xcode 8 中创建一个新扩展,那么您也可能会遇到此问题。

To solve the above scenario...

为了解决上述情况...

Note:All code has to be in the same swift (compatible) version to compile without failure.

注意:所有代码都必须在相同的 swift(兼容)版本中才能编译而不会失败。

That being said, one way you could solve this problem is by sticking to Swift 2.3and then setting your Extension Target's Use Legacy Swift Language Versionto "Yes".

话虽如此,解决此问题的一种方法是坚持使用 Swift 2.3,然后将扩展目标的使用旧版 Swift 语言版本设置为“是”。

You can find that option while Xcode 8 is open as follows:

您可以在 Xcode 8 打开时找到该选项,如下所示:

  1. Select your app project root in the Project Navigator (on the left-hand side)
  2. On the right-hand side, select your extension under the TARGETS section
  3. Once the extension is selected, click on the Build Settingstab
  4. Scroll down and find Use Legacy Swift Language Version? and set it to Yesfrom its drop-down menu.
  5. You can now build the project
  1. 在项目导航器中选择您的应用项目根目录(在左侧)
  2. 在右侧,在 TARGETS 部分下选择您的扩展程序
  3. 选择扩展程序后,单击“构建设置”选项卡
  4. 向下滚动并找到Use Legacy Swift Language Version? 并从下拉菜单中将其设置为Yes
  5. 您现在可以构建项目

Note:You might need to fix the overridden code in the extension templates since they were originally in Swift 3.

注意:您可能需要修复扩展模板中被覆盖的代码,因为它们最初是在 Swift 3 中的。

回答by ShakeMan

Before doing anything...

在做任何事情之前...

(If you can use Xcode 8.0-compatible with your project)

(如果您可以使用与您的项目兼容的 Xcode 8.0)

By default your project is set to Xcode 3.2-compatible

默认情况下,您的项目设置为 Xcode 3.2-compatible

  • Select your app project in the Navigator(on the left-hand side)
  • Select Project Documentin the Utilities Panel(on the right-hand side)
  • Change Project Formatto Xcode 8.0-compatible
  • 导航器中选择您的应用项目(在左侧)
  • 在“实用工具”面板(右侧)中选择“项目文档”
  • 项目格式更改为Xcode 8.0 兼容

Try to build your project.

尝试构建您的项目。

If it doesn't work, try the other solutions proposed.

如果它不起作用,请尝试建议的其他解决方案。

Note:You can even switch back to Xcode 3.2-compatible after fixing the error and it should work, but you "might" have other build problems later.

注意:您甚至可以在修复错误后切换回 Xcode 3.2-compatible,它应该可以工作,但您以后“可能”有其他构建问题。

Recommendation: Before debugging an existing project. Close your project and zip a copy of your project file if you did not create a Git repository when you created your project.

建议:在调试现有项目之前。如果您在创建项目时没有创建 Git 存储库,请关闭您的项目并压缩项目文件的副本。

回答by Samir

I just had the same problem after updating Xcode to 9.3. I fixed the problem simply by just cleaning the build folder. You can do this with Command-Option-Shift-K or in the option menu "Product" -> "Clean" (see screenshot)

将 Xcode 更新到 9.3 后,我遇到了同样的问题。我只是通过清理构建文件夹来解决这个问题。您可以使用 Command-Option-Shift-K 或在选项菜单“产品”->“清洁”中执行此操作(请参见屏幕截图)

You can clean the build folder with Command-Option-Shift-K or in the option menu "Product" ->"Clean"

您可以使用 Command-Option-Shift-K 或在选项菜单“产品”->“清洁”中清理构建文件夹

回答by Clayton J Roberts

I fixed this by deleting the embedded binaries in the project. To do this:

我通过删除项目中嵌入的二进制文件来解决这个问题。去做这个:

  1. Open your workspace/ project in Xcode.
  2. Navigate to the actual project file (with the General, Capabilities, etc. ribbon).
  3. Go to General > Embedded Binaries, remove by selecting on the ones you don't want and then clicking the minus sign.
  1. 在 Xcode 中打开您的工作区/项目。
  2. 导航到实际项目文件(使用 General、Capabilities 等功能区)。
  3. 转到“常规”>“嵌入式二进制文件”,通过选择不需要的文件然后单击减号来删除。

Note 1: You shouldn't have to delete them from the "Linked Frameworks and Libraries" section (they should automatically be removed when you remove them from the "Embedded Binaries").

注意 1:您不必从“链接的框架和库”部分中删除它们(当您从“嵌入式二进制文件”中删除它们时,它们应该会自动删除)。

Note 2: I have a lot of dependencies and am using CocoaPods. I have nothing in the "Embedded Binaries" and only the "Pods_[YourApplicationName].framework" in the "Linked Frameworks and Libraries" section.

注 2:我有很多依赖项并且正在使用 CocoaPods。我在“嵌入式​​二进制文件”中没有任何内容,在“链接的框架和库”部分中只有“Pods_[YourApplicationName].framework”。

回答by ph1lb4

I had various libraries integrated via carthage. However during the process I switched some of them to cocoapods and forgot to remove the old .frameworksfile from the project target.

我通过迦太基集成了各种库。但是在此过程中,我将其中一些切换到 cocoapods 并忘记.frameworks从项目目标中删除旧文件。

Removing them solved the build error.

删除它们解决了构建错误。

回答by user6832423

I had the same problem. My solution was to rename the 'myApp'-directory to 'myAppmyApp' and then I ran the app again. A new 'myApp'-directory was made a the app did run very well again on my iPhone.

我有同样的问题。我的解决方案是将“myApp”目录重命名为“myAppmyApp”,然后再次运行该应用程序。创建了一个新的“myApp”目录,该应用程序在我的 iPhone 上再次运行得非常好。

A difference with your situation might be this: the name of my app, let's say 'myApp' in the directory 'DerivedData' was myApp concatenated with: '-'

与您的情况不同的可能是:我的应用程序的名称,假设目录“DerivedData”中的“myApp”与 myApp 连接:“-”

Maybe this will help you.

也许这会帮助你。

回答by Martin Roma?uk

You need to switch all the dependencies to swift 3. In your case, Alamofire need to be switched to Swift 3branch

您需要将所有依赖项切换到swift 3. 在您的情况下,Alamofire 需要切换到Swift 3分支

回答by Zigii Wong

So I just post the solution I found so far after an hour debugging.

所以我只是发布了我在调试一个小时后找到的解决方案。

Since Xcode 9, this can be tracked by the compiler log.

从 Xcode 9 开始,这可以通过编译器日志进行跟踪。

If you scroll down to the bottom of the compiler log, you will find this issue is caused by type checking crash.

如果向下滚动到编译器日志的底部,您会发现此问题是由类型检查崩溃引起的。

enter image description here

在此处输入图片说明

回答by vmeyer

I had the same error message after adding a Swift 3 version of a framework.

添加 Swift 3 版本的框架后,我收到了相同的错误消息。

My target framework search pathwas still configured to find both swift 2 and swift 3 version of the same framework, so my project got stuck on swift 2.3 version.

我的目标framework search path仍然配置为查找同一框架的 swift 2 和 swift 3 版本,所以我的项目卡在 swift 2.3 版本上。

For me, the solution has been to remove the old framework from my project directory and delete its folder reference from the framework search path.

对我来说,解决方案是从我的项目目录中删除旧框架,并从framework search path.