Universal library for iOS and AppleTV?

Is it possible to distribute a single library that works on both iOS and AppleTV? I know the APIs aren't quite the same, but I'm wondering if I do enough weak-linking and if-defing in the headers if I can get the same .a/framework working across iOS and AppleTV. I'm still looking at this, but having trouble getting Xcode launching, so I thought I'd put the question out there on the forums.


We're a library vendor and I'm just wondering if I'd have to do an AppleTV specific library, or if I could just have developers use the same single distribution.

Answered by in 52309022

Just a few clarifications here.. The answer is yes and no - depending on exactly which question you are asking.


Any static library or framework that you link against in your tvOS application *must* also be built against the tvOS SDK. You cannot submit a tvOS application that links against a framework that was built for iOS. During the beta period, Xcode will simply warn when it sees you trying to do this. That way, you can get started on development now, while you wait for your dependent libraries to be updated for tvOS.


However, it is possible to create a framework/library target that successfully builds for both OSs. I believe Xcode will require you to create a separate target for each platform - but if you're careful to call only API that are available on both, you should be fine.


Make sense?

Yes, this should be possible.

I bet that lipo on the commandline would work just fine.


I've been pondering that method for making a single static lib with armv7/arm64/i386 all together for device and simulator. But, Xcode won't magically join them together because it treats device and simulator so differently.


lipo is a magic tool! 🙂

My guess is (and it's inferred in the reply) that in since iOS devices and the AppleTV share the same ARM processors, they're going to share the same architecture slices, so I don't think lipoing would be even necessary, or even work if the AppleTV and iOS slices want to occupy the same part of the binary!

Please do ensure that any libraries that you do create are done so with bitcode enabled, as it is required for the tvOS platform.

Accepted Answer

Just a few clarifications here.. The answer is yes and no - depending on exactly which question you are asking.


Any static library or framework that you link against in your tvOS application *must* also be built against the tvOS SDK. You cannot submit a tvOS application that links against a framework that was built for iOS. During the beta period, Xcode will simply warn when it sees you trying to do this. That way, you can get started on development now, while you wait for your dependent libraries to be updated for tvOS.


However, it is possible to create a framework/library target that successfully builds for both OSs. I believe Xcode will require you to create a separate target for each platform - but if you're careful to call only API that are available on both, you should be fine.


Make sense?

Yes, that makes sense, and is also valuable to know for working with any customer requests for tvOS support. Thanks!

Universal library for iOS and AppleTV?
 
 
Q