Xcode如何将目标打包为.framework(而不是.a库) [英] Xcode how to package the target as a .framework (instead of .a library)

查看:785
本文介绍了Xcode如何将目标打包为.framework(而不是.a库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Universal Framework项目,该项目包含一个库作为其主要目标,并且在Products下是带有'lib'前缀和.a扩展名的库.请参见下面的屏幕截图:

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:

我正在使用一个第三方项目,该项目包含一个框架作为目标,并且在Products下是具有.framework扩展名的框架.请参见下面的屏幕截图:

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:

在构建设置"中四处查看,我可以看到打包"和链接"下都有差异,其他地方可能还有更多差异.因此,这让我很好奇如何建立一个项目来生成.framework而不是.a库.

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.

刚向我指出,我正在尝试创建一个 static 框架.是否有人知道一个好的教程,博客或书籍,可以指导我完成更改目标产品并帮助我理解差异的步骤?

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?

谢谢.

推荐答案

Xcode 6和最新的平台SDK允许构建iOS的(动态)框架.今年的WWDC有几场会议讨论了如何使用框架.

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.

带有iOS SDK的Xcode的早期版本不直接支持为iOS构建框架目标.虽然可以构建静态iOS框架,但它不受支持并且有些脆弱.使用Xcode 6和最新的iOS SDK,构建框架就像创建新框架目标一样容易.在以前版本的Xcode中,它涉及的程度更多,并且Xcode本身不会在所有应有的位置识别该构建产品.将这些框架用作依赖项等,在Xcode的早期版本中是行不通的.

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.

使用Xcode 5构建 static 框架非常类似于构建静态库.特定于静态框架的重要项目配置设置为:

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

  1. 从静态库目标开始.确保您的代码可以构建为静态库.
  2. 创建一个新的捆绑包目标.
  3. 从版本中删除平台,基本SDK,包装扩展,产品名称(如果需要)和OS X部署目标设置.
  4. 最好将上述设置应用到该目标,方法是使用构建配置文件.
  5. 将您的代码,资源等添加到目标.检查目标的构建阶段,以确保一切都在您期望的位置.对于标头,请使用标头构建阶段,而不要使用复制文件构建阶段.
  6. 如果您使用的是前缀标头,请确保为目标平台使用正确的标头(即,UIKit.h而不是Cocoa.h)

这将构建一个静态框架产品. Xcode 5不能将其用作方案等的依赖项.框架的文件布局将与动态框架不同.

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.

这篇关于Xcode如何将目标打包为.framework(而不是.a库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆