简体   繁体   English

将静态库目标转换为Xcode项目中的框架目标

[英]Convert a static library target into a framework target in an Xcode project

I have a an Xcode project which produces a static library. 我有一个Xcode项目,它生成一个静态库。 My team plans all new development in Swift. 我的团队计划在Swift中进行所有新开发。 It is not possible to add Swift files to the static library project . 无法将Swift文件添加到静态库项目中 We are dropping support for iOS 7, so it is now possible to include frameworks in our iOS app. 我们正在放弃对iOS 7的支持,因此现在可以在我们的iOS应用程序中包含框架。 Therefore, I intend to convert my static library project to a framework project. 因此,我打算将我的静态库项目转换为框架项目。

I have looked but I cannot find any tools or advice for how to perform this conversion. 我看过,但我找不到任何有关如何执行此转换的工具或建议。 The static library is large (more than 100 .m files). 静态库很大(超过100个.m文件)。

I'm hoping for a better answer than create a new parallel framework target. 我希望得到一个更好的答案,而不是创建一个新的并行框架目标。 I've attempted this twice. 我试过两次。 The first time as a swift target, but I wasn't able to easily import all the Objective C files. 第一次作为一个快速的目标,但我无法轻松导入所有的Objective C文件。 Next, as an Objective C target, but there is no .pch anymore. 接下来,作为Objective C目标,但不再有.pch。

To convert the static/dynamic linked framework from static linked library, 要从静态链接库转换静态/动态链接框架,

  1. Add a new cocoa touch framework as a TARGET in your existing static linked library project. 在现有的静态链接库项目中添加一个新的cocoa touch框架作为TARGET。
  2. In the Build Phases, adding all the .m, .mm, .c, .cpp, .metal, etc. into "\\Build Phases\\Compile Sources" phase of your static linked framework target. 在Build Phases中,将所有.m,.mm,.c,.cpp,.metal等添加到静态链接框架目标的“\\ Build Phases \\ Compile Sources”阶段。
  3. Put the headers that you want to exposed in to "\\Build Phases\\Headers". 将要公开的标题放在“\\ Build Phases \\ Headers”中。
  4. For dynamic linked framework, remember to check the Mach-O Type setting in your Build Settings. 对于动态链接框架,请记住在Build Settings中检查Mach-O Type设置。 If you are going to use swift, you need to make sure the Mach-O type is set as dynamic library so that it will become a dynamic linked framework. 如果要使用swift,则需要确保将Mach-O类型设置为动态库,以使其成为动态链接框架。 For static linked framework, you'll need to set the Mach-O type as static library, but you cannot use swift in the converted static linked framework (only objective-c, objective-c++, C++, C, etc. are allowed). 对于静态链接框架,您需要将Mach-O类型设置为静态库,但不能在转换后的静态链接框架中使用swift(只允许使用objective-c,objective-c ++,C ++,C等) 。

Then for the app that wants to use this framework just need to include the headers as #import and add the framework into "Build Phases\\Link Binary With Libraries" of your App Target. 然后,对于想要使用此框架的应用程序,只需将标头包含为#import,并将框架添加到App Target的“Build Phases \\ Link Binary With Libraries”中。 If the converted framework is dynamic linked framework, you will need to put it into "Embedded Binaries". 如果转换的框架是动态链接框架,则需要将其放入“嵌入式二进制文件”中。

I saw that someone created the framework manually, creating a module.framework file and copying all the header files in a module.framework/Headers folder. 我看到有人手动创建了框架,创建了module.framework文件并将所有头文件复制到module.framework / Headers文件夹中。 This solution seems to work, the project can import correctly the files and see them as a framework correctly. 这个解决方案似乎有效,项目可以正确导入文件并正确地将它们视为框架。

I'm not sure this is the best way to do it tough, I'm trying it on a big project that ATM is importing the static library through cocoapods, but it seems like I have some problem with the visibility of some of the classes using the framework. 我不确定这是做这件事的最好方法,我正在尝试ATM通过cocoapods导入静态库这个大项目,但似乎我对某些类的可见性有些问题使用框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM