18

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?

enter image description here

Rasto
  • 17,204
  • 47
  • 154
  • 245
  • 1
    @HobbestheTige Then I would suggest you upvote the question ;) No, I did not solve it yet, but will set a bounty on this one in next few days. Except it is a mystery and I cannot see frameworks in "Embedded binaries" I also get compile warning every time I compile. Therfore I definitelly want to solve it. – Rasto Nov 21 '14 at 22:44
  • 1
    See: [Xcode won't add “Embedded binary” after deleting “DerivedData”](http://stackoverflow.com/q/27782284/89035) – Richard Stelling Jan 05 '15 at 15:12
  • @drasto It would be good to get http://stackoverflow.com/a/27796165/89035 marked as the accepted answer :D – Richard Stelling Nov 01 '16 at 10:35

6 Answers6

15

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
Community
  • 1
  • 1
Richard Stelling
  • 25,607
  • 27
  • 108
  • 188
  • that one solved so many problems for me ! I also deintegrated and reinstalled my Pods during the course and now everything works as expected on simulator and on device – hakkurishian Mar 11 '17 at 11:13
5

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!

Hobbes the Tige
  • 3,753
  • 2
  • 22
  • 21
  • 1
    Yup, this did the trick. One important note is you need to build the framework for "iOS Device" instead of for a specific simulator device like iPhone 6. – Kevin Qi Sep 30 '15 at 19:40
  • No need to remove projects from the workspace like @rjstelling suggests. Just rebuild the frameworks using an iOS (Generic) device. – Daniel Wood Feb 09 '16 at 11:43
1

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

NumeroUno
  • 11
  • 1
1

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.

Mark Lilback
  • 1,154
  • 9
  • 21
  • `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` that's the key! thanks! – Jan Sep 01 '16 at 09:45
0

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.

-3

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

Paul de Lange
  • 10,613
  • 10
  • 41
  • 56
  • True, they are not separate targets, they are separate projects. But that is exactly how I want it to be (besides it worked before). The frameworks are really developed separately and shared between projects. You can think of them as external libraries which might even be compiled (without sources available to me). I only have them in the same workspace for convinience as I find a bug in the frameworks from time to time so I do not have to swich workspace. If you watch "Session 233: Sharing code between iOS and OS X" they use same setup as I am trying to get. – Rasto Nov 20 '14 at 13:29
  • I agree with you and wanted to do the same – Paul de Lange Nov 21 '14 at 04:55