Here's the obvious method:
- have app and custom framework projects in the same workspace
- in the app main target, add the framework to General->Embedded Binaries
(as expected, this also adds the framework to General->Linked Frameworks and Libraries, and to the two build phases 'Link Binary With Libraries' and 'Embed Frameworks'
This worked fine in the simulator, then crashed on the device with:
dyld: Library not loaded: @rpath/XX.framework/XX Referenced from: /var/containers/Bundle/Application/E551758E-ED3C-486E-B6AE-856B5872C14D/AA.app/AA Reason: no suitable image found. Did find: /private/var/containers/Bundle/Application/E551758E-ED3C-486E-B6AE-856B5872C14D/AA.app/Frameworks/XX.framework/XX: mach-o, but wrong architecture
With use of lipo etc and then squinting at the Xcode General tab (hard to read because the paths don't wrap, and the mouseover path display is erratic), it's easy to figure out what's going on: when you add a framework to the 'Embed' build phase, Xcode actually hard-codes the path to the last build artifact of the framework. So if it happened to be built for the simulator, sure enough an x64 framework is what gets embedded in future builds of the main app, regardless of the architecture you're actually building for.
It's also easy enough to see fix this: forget about Xcode's embedding support, just link the framework. Then add a build script phase to copy the built framework into the app bundle, using the appropriate build variables to pick the right architecture.
But this seems like such a catastrophic error on Xcode's part, given that it does 'support' embedding frameworks, I can't help wonder if I'm missing something. Is there an 'official' method of embedding custom frameworks in an iOS app that actually works? Surely there must be?
(using most recent versions of everything)