问题
I have a Universal Framework project that contains a library as its main target and under Products is the library with 'lib' prefix and a .a extension. See screenshot below:
I am using a 3rd party project that contains a framework as its target and under Products is the framework with a .framework extension. See screenshot below:
Poking around in the Build Settings, I can see there are differences under Packaging and also under Linking and there may be more differences elsewhere. So, this got me curious about how to set up a project to produce a .framework instead of a .a library.
I was just pointed out to me that I am trying to create a static framework. Does anybody know of a good tutorial or blog or book that can guide me through steps to change the target product and help me understand the differences?
Thank you.
回答1:
Xcode 6 and the newest platform SDKs allow building of (dynamic) frameworks for iOS. There are several sessions from this year's WWDC that cover how to use frameworks.
Previous versions of Xcode with the iOS SDK did not directly support the building of framework targets for iOS. While it was possible to build static iOS frameworks, it was unsupported and somewhat fragile. With Xcode 6 and the latest iOS SDK, building a framework is as easy as creating a new framework target. In previous versions of Xcode, it was a bit more involved and Xcode itself would not recognize the build product in all of the places it should. Using those frameworks as dependancies, etc. just did not work in previous versions of Xcode.
Static frameworks in Xcode 5
Building a static framework using Xcode 5 is a lot like building a static library. The important project configuration settings specific to a static framework are:
SDKROOT = iphoneos
ONLY_ACTIVE_ARCH = NO
SUPPORTED_PLATFORMS = iphonesimulator iphoneos
VALID_ARCHS = arm64 armv7 armv7s x86_64 i386
LINK_WITH_STANDARD_LIBRARIES = NO
MACH_O_TYPE = staticlib
WRAPPER_EXTENSION = framework
- Start with a static library target. Make sure your code can build as a static library.
- Create a new bundle target.
- Remove the Platform, Base SDK, wrapper extension, product name (if you want) and OS X Deployment Target settings from the build.
- Apply the settings above to this target, preferably by using a build configuration file.
- Add your code, resources, etc. to the target. Check the build phases of the target to make sure everything is where you expect it. For headers, use a headers build phase and not the copy file build phase.
- If you are using a prefix header, make sure it's using the correct headers for your target platform (i.e. UIKit.h not Cocoa.h)
This will build a static framework product. Xcode 5 will not be able to use this as a dependency in schemes, etc. The file layout of the framework will be different from a dynamic framework.
回答2:
I found a great tutorial on how to build custom iOS frameworks. Even though the finished product is a Universal Framework, which is NOT my ultimate goal, the author chooses to create an empty project. One that does not include a Target Product. There are several options for adding Target Products and I wasn't sure which one to use. So I added all the Target Products that have the Bundle icon and compared the properties and settings with the framework Target Product in the QLM project. It looks like QLM used the Bundle Target Product. I'm still working through the properties and settings, though, so not sure what issues I might face.
Anyway, I'm posting this as a possible answer in hopes that someone may have additional information for creating this type of Project Target Product. I encourage anyone with experience creating this type of Target Product who can answer the question to do so. Any additional information warrants an up vote and/or the answer points.
Thank you.
来源:https://stackoverflow.com/questions/25148583/xcode-how-to-package-the-target-as-a-framework-instead-of-a-library