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

自闭症网瘾萝莉.ら 提交于 2019-12-31 19:27:34

问题


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.

Now, I have XCode 6.1. Recently, I deleted DerivedData folder in ~/Library/Developer/Xcode folder 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.

I tried to solve it by removing my the 2 libraries from Embedded Binaries of the app project - and I cannot add them back. Clicking + button under Embedded Binaries in 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 Binaries or Linked Frameworks and Libraries not 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.

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?


回答1:


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:

  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



回答2:


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.

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!




回答3:


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




回答4:


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

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.




回答5:


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.

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).

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.

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.




回答6:


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

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



来源:https://stackoverflow.com/questions/26983628/cannot-add-embedded-binaries-other-projects-to-project-dependencies-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!