62

I'm using Alamofire in a Swift project, and part of their manual installation instructions are to add Alamofire under Embedded Binaries in the General tab for my application target.

enter image description here

What are Embedded Binaries?

Rian Rizvi
  • 9,989
  • 2
  • 37
  • 33
Doug Richardson
  • 10,483
  • 6
  • 51
  • 77

3 Answers3

56

Embedded binaries are binary files that are copied to your application bundle when you build the project. Use embedded binaries when your application relies on third-party frameworks so people can use your application without needing those frameworks installed on their machine. Embedded binaries keep users from having to manually install third-party frameworks. Your application uses the framework you embedded.

In your Alamofire example your application relies on Alamofire. If you didn't embed the Alamofire framework, nobody would be able to use your application unless they installed Alamofire manually. By embedding Alamofire with your application everyone can run your application.

Swift Dev Journal
  • 19,282
  • 4
  • 56
  • 66
  • 3
    The way I recall doing this in the past on OS X on recently with another 3rd party framework on iOS is to build the framework and then create a copy file Build Phase to copy the framework under the "Frameworks" destination. Is this supposed to be a replacement for that? It does seem easier than the way I used to do it. – Doug Richardson May 11 '15 at 17:47
  • 2
    Yes, it's supposed to be a replacement to the Copy Files build phase for copying binary files, such as frameworks, libraries, and command-line tools. – Swift Dev Journal May 11 '15 at 18:00
  • 1
    Have you seen any documentation on this Xcode feature? I haven't found any. – Doug Richardson May 11 '15 at 18:03
  • I haven't seen any documentation on it, but I haven't looked hard for documentation on it. – Swift Dev Journal May 11 '15 at 18:16
  • What if I link to a subproject (which is a Cocoa Touch Framework, so it's a dynamic library+some assets)? Do I still need to use Embedded Binaries feature? I tried to launch my app without it and it runs just fine on a simulator, but not sure if it's because of simulator or because XCode embeds it in some other, hidden way because it's a subproject. – JustAMartin Jan 19 '17 at 21:58
  • @JustAMartin I have never used subprojects. Ask a new question, and someone else may have an answer for you. – Swift Dev Journal Jan 20 '17 at 17:46
  • 1
    I found one more curious thing in XCode 8. "General -> Embedded binaries" and "Build Phases -> Embed Frameworks" seem to be linked, because if you drag a .framework into one of these places, it automatically appears in the other place also; and in "Embed Frameworks" it automatically enable "Code sign on copy" (signing is important for building your app archives for distribution). – JustAMartin Jan 20 '17 at 18:52
  • Somehow I'd ended up with my app's own frameworks in the 'Linked Frameworks' section but not 'Embedded Binaries' (which I knew nothing about). I guess the auto-adding behaviour JustAMartin describes didn't happen for me. Spent ages watching my Xcode UI tests fail to start with the error "dyld: Library not loaded: @rpath/MyFramework.framework ... Reason: image not found". The fix was to add the frameworks to Embedded Binaries as well! – chriskilding Aug 24 '17 at 22:16
  • The other way around does seem to work: If you add it to "Embedded Binaries," Xcode will add it to "Linked Frameworks and Binaries." You can have it in only "Embedded" and not "Linked," though (if you remove it from Linked). I don't know why that works. And "Embedded Binaries" is still undocumented in the Xcode help. – Oscar Jan 18 '19 at 03:34
51
  • "Binary" means: compiled code — as opposed to "source code", which is what you are working with when you write code as text.

    They could have given you source code and let you compile it, but they didn't; they are keeping the source code secret, so they've given it all to you after compilation, so that you can't read it.

  • "Embedded" means: to be included inside your app bundle, by copying them into it at build time.

    So, they are handing you some compiled code (frameworks) and telling you how to include them inside your app bundle. These frameworks, unlike Cocoa's frameworks, do not already exist on the device, so if you don't include them inside the app, they won't be present and your app would be unable to call into them.

    Contrast this to Cocoa's frameworks. They, too, are compiled code. But they do already exist on the device. Therefore they are not embedded inside your app; they are merely linked (and, if they appeared, would appear in the next group, Linked Frameworks and Libraries).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    The fact they're called Embedded "Binaries" as opposed to Embedded "Frameworks" makes me think they're intended to be more general than just for frameworks. Do you know if they're used for anything else besides frameworks? Also, do you have any points to documentation on this? I haven't been able to find any. – Doug Richardson May 11 '15 at 17:43
  • 1
    In the more general case, you can also embed a library file. – matt May 11 '15 at 17:45
5

Embedding binaries copies the entire framework to the target.

A framework is a hierarchical directory that encapsulates a dynamic library, header files, and resources, such as storyboards, image files, and localized strings, into a single package. Apps using frameworks need to embed the framework in the app's bundle.

So, when you embed a framework in your app, it increases the size of your app because it is copied to you app bundle. In most of the scenarios we will be using this sections when we are using third party framework.

When we add a framework to Embedded Binaries it automatically adds that framework to Linked Frameworks and Libraries also.

Refer to apple documentation for more details: https://developer.apple.com/library/archive/technotes/tn2435/_index.html

Shubham Mishra
  • 1,303
  • 13
  • 24