无法将嵌入式二进制文件(其他项目)添加到 XCode 中的项目依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26983628/
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-09-15 06:11:57  来源:igfitidea点击:

Cannot add embedded binaries (other projects) to project dependencies in XCode

iosxcodeprojectproject-managementlinker-errors

提问by Rasto

I have an XCode workspace created with XCode 6.0.1. It constains 2 (Swift) libraries and one iOS app (Swift) that depends on those 2 libraries. I had stable setup that allowed me to run the iOS app on both iPhone and simulators: The 2 library projects were added as Embedded Binaries(see picture) of the app.

我有一个使用 XCode 6.0.1 创建的 XCode 工作区。它包含 2 个 (Swift) 库和一个依赖于这两个库的 iOS 应用程序 (Swift)。我有稳定的设置,允许我在 iPhone 和模拟器上运行 iOS 应用程序:这 2 个库项目被添加为应用程序的嵌入式二进制文件(见图)。

Now, I have XCode 6.1. Recently, I deleted DerivedDatafolder in ~/Library/Developer/Xcodefolder while XCode was running. After that my workspace did not work - the iOS app would fail to compile and I got linker error saying it cannot find the library projects.

现在,我有 XCode 6.1。最近,我DerivedData~/Library/Developer/Xcode运行 XCode 时删除了文件夹中的文件夹。之后我的工作区不起作用 - iOS 应用程序将无法编译,我收到链接器错误,说它找不到库项目。

I tried to solve it by removing my the 2 libraries from Embedded Binariesof the app project - and I cannot add them back. Clicking + button under Embedded Binariesin project settings displays workspace projects correctly but selecting and adding my library project does not add them to the list of Embedded Binaries. I have solved the linker error by creating new workspace. The app compiles but how it links the libraries is a mystery to me: They are not in listed Embedded Binariesor Linked Frameworks and Librariesnot in the Frameworks search path. There appears to be no link between the app and the libraries it needs (and obviously have as it compiles) except that libraries projects are in the same workspace.

我试图通过从应用程序项目的嵌入式二进制文件中删除我的 2 个库来解决它- 我无法将它们添加回来。单击项目设置中Embedded Binaries下的 + 按钮可正确显示工作区项目,但选择并添加我的库项目不会将它们添加到Embedded Binaries列表中。我通过创建新工作区解决了链接器错误。该应用程序可以编译,但它如何链接库对我来说是个谜:它们不在列出的嵌入式二进制文件链接的框架和库中,不在框架搜索路径中. 除了库项目位于同一个工作区之外,应用程序和它需要的库之间似乎没有链接(并且显然在编译时有)。

Why I cannot add library projects to Embedded Binaries? Is it normal in XCode 6.1 that dependency projects just compile and gets embedded into an app without being listed or linked anywhere?

为什么我不能将库项目添加到嵌入式二进制文件?在 XCode 6.1 中,依赖项目只是编译并嵌入到应用程序中而没有在任何地方列出或链接,这是否正常?

enter image description here

在此处输入图片说明

回答by Richard Stelling

This is a summary of my answer to the question Xcode won't add “Embedded binary” after deleting “DerivedData”, see the original question and answer for more context and information:

这是我对删除“DerivedData”后Xcode不会添加“Embedded binary”问题的回答的摘要,有关更多上下文和信息请参阅原始问题和答案

  1. Remove all framework projects from the workspace
  2. Perform a "clean build"and/or remove the "DerivedData"
  3. Add project back into the workspace
  4. Build the project (possibly optional)
  5. In the General tab of the app target click the + under "Linked Frameworks and Libraries", select the framework.
  6. Build and run in the Simulator (there should be no issues building or running)
  7. Build and run for device (this might cause a crash due to the framework not being correctly linked, ignore this crash)
  8. Click the + under "Embedded Binaries", select the framework. This should add it to the project (possible duplicate under "Linked Frameworks and Libraries")
  9. Repeat for all required frameworks
  10. Once building and running (on device) is confirmed you can remove any duplicate (and/or red) frameworks in the Project Navigator or target General tab
  1. 从工作区中删除所有框架项目
  2. 执行“干净构建”和/或删除“DerivedData”
  3. 将项目添加回工作区
  4. 构建项目(可能是可选的)
  5. 在应用程序目标的常规选项卡中,单击“链接的框架和库”下的 + ,选择框架。
  6. 在模拟器中构建并运行(构建或运行应该没有问题)
  7. 为设备构建并运行(这可能会由于框架未正确链接而导致崩溃,请忽略此崩溃)
  8. 单击“嵌入式二进制文件”下的 + ,选择框架。这应该将它添加到项目中(可能在“链接的框架和库”下重复)
  9. 对所有必需的框架重复
  10. 确认构建和运行(在设备上)后,您可以删除项目导航器或目标常规选项卡中的任何重复(和/或红色)框架

回答by Hobbes the Tige

Ok, I ran into the same problem as you. After deleting the derived data, I could not re-link my binaries again. I think the reason is because the derived data is where the binaries are written to and linked against in your project.

好的,我遇到了和你一样的问题。删除派生数据后,我无法再次重新链接我的二进制文件。我认为原因是派生数据是在您的项目中写入和链接二进制文件的地方。

What I did to solve was to select my Framework as my build target. After building it, the Framework target turned from red to black. I can see in your screenshot it is red, meaning it has not been compiled into a binary and written on disk.

我要解决的是选择我的框架作为我的构建目标。构建完成后,Framework 目标从红色变为黑色。我可以在你的截图中看到它是红色的,这意味着它没有被编译成二进制文件并写入磁盘。

Once I did this, I was able to re-link the Framework to my Project because there was a reference to it on disk. Hope this helps!

一旦我这样做了,我就能够将框架重新链接到我的项目,因为磁盘上有对它的引用。希望这可以帮助!

回答by NumeroUno

Clean your projects & build your framework first. Thereafter you can embed it.

首先清理您的项目并构建您的框架。此后,您可以嵌入它。

回答by Mark Lilback

Here is how I solved the problem:

这是我解决问题的方法:

  1. Build the framwork.

  2. Open the build folder and drag built framework into the app project (so it uses the path to DerivedData).

  3. Add the framework to the list of embedded frameworks.

  4. In the Finder, do a Show Contents on the app's xcodeproj file, then open project.pbxproj in your favorite text editor.

  5. Find the line with the long DerivedData path. Change it so there is no name, the path is the framework name, and source tree is BUILT_PRODUCTS_DIR

  1. 构建框架。

  2. 打开构建文件夹并将构建的框架拖到应用程序项目中(因此它使用 DerivedData 的路径)。

  3. 将框架添加到嵌入式框架列表中。

  4. 在 Finder 中,对应用程序的 xcodeproj 文件执行 Show Contents,然后在您喜欢的文本编辑器中打开 project.pbxproj。

  5. 找到具有较长 DerivedData 路径的行。改成没有名字,路径是框架名,源码树是BUILT_PRODUCTS_DIR

Xcode should notice the change and the library in the app project will be black instead of red and will now build and run properly.

Xcode 应该注意到这一变化,应用项目中的库将是黑色而不是红色,现在可以正常构建和运行。

回答by Martin-Gilles Lavoie

I have a very similar issue and fixed it just last night. Decided to come back to this thread and offer my workaround, as rjstelling's solution above did not help my case.

我有一个非常相似的问题,并在昨晚修复了它。决定回到这个线程并提供我的解决方法,因为上面 rjstelling 的解决方案对我的情况没有帮助。

I have a workspace that contains two frameworks and one application. The App was making use of both frameworks happily for a while until I got hit by a mysterious compile eror where it decided that adding a property access to an instance variable called "cube" of a class type found in one of the framework, made access to "_cube" impossible (complaining it was not declared, while it had actually worked previously in a setter method).

我有一个包含两个框架和一个应用程序的工作区。该应用程序愉快地使用了这两个框架一段时间,直到我遇到一个神秘的编译错误,它决定将属性访问添加到在其中一个框架中找到的类类型的名为“cube”的实例变量中,进行访问到“_cube”是不可能的(抱怨它没有被声明,而它实际上以前在 setter 方法中工作过)。

Long story short, after a clean, somehow the workspace/app project lost track of the embedded framework of my iOS 8+ project. Removing the embedded framework was the last straw in that line of failure, causing my project to no longer allow be to select any frameworks for embedding.

长话短说,经过清理后,工作区/应用程序项目以某种方式失去了对我的 iOS 8+ 项目的嵌入式框架的跟踪。删除嵌入式框架是那条失败的最后一根稻草,导致我的项目不再允许选择任何框架进行嵌入。

Reverting the project & workspace to an earlier version did not get rid of the voodoo.

将项目和工作区恢复到早期版本并没有摆脱伏都教。

I ended up adding the to-be-embeded framework projects in the main app project (as files) and introduced target dependencies on the frameworks.

我最终在主应用程序项目中添加了要嵌入的框架项目(作为文件),并在框架上引入了目标依赖项。

I was then able to re-embed the frameworks and link.

然后我能够重新嵌入框架和链接。

As for the _cube thing, I had to specify a getter for the property and @synthesize the property to a different name. I dont have an explanation for this one.

至于 _cube 的事情,我必须为该属性指定一个 getter,并将该属性@synthesize 指定为不同的名称。我对此没有解释。

回答by Paul de Lange

It's probably because your framework is a separate project and not a separate target. Try watching carefully Session 416: Building a Modern Frameworkat around minutes 34-36. It will show you how to set it up correctly.

这可能是因为您的框架是一个单独的项目,而不是一个单独的目标。尝试仔细观看第 416 场会议:在 34-36 分钟左右建立现代框架。它将向您展示如何正确设置它。

This makes it a bit confusing if you wanted to share a framework across multiple projects by the way

顺便说一句,如果您想在多个项目之间共享一个框架,这会让人有点困惑