iOS universal framework with iphoneos and iphonesimulator architectures
Asked Answered
W

1

7

xcodebuild can build a project with sdk set to either iphoneos or iphonesimulator but not both, so in order to generate a framework containing armv7 arm64 and i386 x86_64 architectures, I have to run xcodebuild twice and then use lipo to combine all the architectures into 1 universal binary. I see commercial framework that does this but it result in an incorrect info.plist file because it has a field, CFBundleSupportedPlatforms and all signs point to it only containing 1 value, e.g., CFBundleSupportedPlatforms = ( "iPhoneSimulator" ).

Seems like lipo shouldn't be used in this manner because it isn't officially supported by xcodebuld. Is there a better way to build a framework to contain all architectures?

Woodnote answered 22/7, 2015 at 23:12 Comment(0)
A
5

I follow the question, but I suppose I am a bit puzzled why you want to unnecessarily bloat a single .framework with simulator-only i386 and x84_64 slices that are really only relevant to your development builds. Would you by chance be wanting to distribute a framework to other developers and want to make it work on simulator as well as device?

If so, you are on the right track with using lipo to join the thin binaries for device together or to join the thin binaries for simulator together, but shouldn't be trying to spawn one single device and simulator framework. Apple's own use of SDKs and Frameworks serves as the guide here. Within Xcode, there are two different platform SDKs -- iPhoneOS.platform and iPhoneSimulator.platform that contain the SDKs with only the slices for the relevant target architectures:

Xcode's Platform Options

You can drill into each of these folders and find the UIKit frameworks do indeed follow the per-platform idea and are conditionally linked based on the SDK that is in use:

UIKit Lipo

I'd further guess that you wanted to have one universal, all-architectures framework so that consuming developers didn't have to remember to swap out one .framework file for another depending on how they were compiling the app. The great news is that you can use conditional linking flags to be able to affect this without needing to do file-system swaps!

As folks adopt your library, part of the setup should be to use conditional linking -- Within the OTHER_LINKER_FLAGS option you can have per-configuration (Debug, Release, Ad-Hoc, etc.) build settings and can also have per-Architecture or per-SDK specific settings too:

Other Linker Flags

To get access to these SDK-specific settings you'll need to click the + next to each of your build configurations where you want to custom tailor framework linking. You can then select the appropriate SDKs from the dropdown list and add your linker flags for each of the two target frameworks.

Alonaalone answered 24/7, 2015 at 22:58 Comment(5)
Thank you for your detailed answer. You guessed right, I am considering it to distribute one framework to other developers but what you said makes sense. One thing though, your paths to iPhoneOS.platform and iPhoneSimulator.platform are no longer there for Yosemite 10.10.4, Xcode 6.4, any idea where they might be?Woodnote
@Woodnote Looks like you might be basing that off the Finder screenshots; take a peek at the Terminal screens to get the full path.Alonaalone
Yep, you are right again, thanks for all your help. I should mention that commercial developers like Crashlytics, Shinobi Charts, and PSPDFKit are packaging both platforms into 1 binary and framework which is counter to Apple own frameworks.Woodnote
@BryanMusial So what goes in the linker flags settings? I presume I compile 2 versions of my lib: lib-sim.framework and lib-device.framework and copy both of these into my client project? But then the build phases section 'link binary with libraries' doesn't allow a per sdk setting, so I don't see how I use one version for sim and another for device?Diathermic
I am also confused about that same thing as @Brynjar. I am not sure what goes into the linker flags to exclude each framework in the appropriate case.Lindblad

© 2022 - 2024 — McMap. All rights reserved.