如何创建静态库,并且可以在 ios 中的任何项目上仅添加 .a 文件.
How can I create static library and can add just .a file on any project in ios.
我试过这样做,但做不到.
I tried doing this but couldn't do it.
提前致谢
如果你想创建静态库,请参考链接 http://jaym2503.blogspot.in/2013/01/how-to-make-universal-static-library.html
if you want create static lib mean refer the link http://jaym2503.blogspot.in/2013/01/how-to-make-universal-static-library.html
第 1 步:创建一个新项目,将其命名为Logger"
Step 1 : Create a New Project, Named it "Logger"
第 2 步:创建类
您可以创建任意数量的类,在我们的教程中,我们将创建一个名为Logger"的类.所以,现在我们的资源中应该有两个文件.1.记录器.h2. 记录器.m
You can create as many classes you wants, In our tutorial we will create one class named "Logger". So, now two files should be in our resource. 1. Logger.h 2. Logger.m
第 3 步:将一些有用的代码放入类中
Step 3 : Put some useful code into Classes
第 4 步:创建新目标
Step 4 : Create New Target
从文件菜单创建新目标.
Create New Target from File Menu.
新目标选择 Cocoa Touch 静态库
New Target Select Cocoa Touch Static Library
第 5 步:将文件添加到编译资源
Step 5 : Add files to Compile Resource
选择静态库的Logger"目标转到构建阶段在 Complied Sources 部分,添加所有 .m 和 .mm 文件.在 Copy Files 部分,添加所有 .h 文件和资源文件.
Select "Logger" Target of Static Library Go to Build Phases In Complied Sources section, Add all the .m and .mm files. In Copy Files section, Add all the .h files and resource files.
构建阶段
第 6 步:使用静态库目标编译项目
Step 6 : Compile Project with Static Library Target
为 iOS 设备编译项目为模拟器编译项目您可以在 build 文件夹中找到两个不同的 .a 文件.
Compile Project for iOS Device Compile Project for Simulator You can find two different .a files generated in build folders.
查找 .a 文件
第 7 步:使静态库通用
Step 7: Make Static Library Universal
您现在可以找到两个不同的库,一个用于模拟器,一个用于 iOS 设备.
You can find two different library now, one is for simulator and one is for iOS devices.
创建一个新文件夹并将其命名为 LoggerMerge.将Debug-iphoneos文件夹的libLogger.a
文件复制到LoggerMerge"重命名为libLogger_device.a将Debug-iphonesimulator文件夹的libLogger.a
文件复制到LoggerMerge"重命名为libLogger_simulator.a使用终端打开 LoggerMerge 文件夹在命令下方开火lipo -create "libLogger_simulator.a
" "libLogger_device.a
" -output "libLogger.a
"
Create a New Folder and name it LoggerMerge.
Copy libLogger.a
file of Debug-iphoneos folder to "LoggerMerge" rename it to libLogger_device.a
Copy libLogger.a
file of Debug-iphonesimulator folder to "LoggerMerge" rename it to libLogger_simulator.a
Open LoggerMerge folder with Terminal
Fire below command
lipo -create "libLogger_simulator.a
" "libLogger_device.a
" -output "libLogger.a
"
现在,您可以在 LoggerMerge 文件夹中找到 libLogger.a,这是通用静态库文件.现在,您只需要一件事就是标题,请参见上面的屏幕截图,在两个构建文件夹中都有一个名为 include 的文件夹.只需从该文件夹中复制头文件即可.
Now, you can find libLogger.a in LoggerMerge folder, this is Universal static library file. Now, Just one thing you need is headers, See above screenshot there is folder called include in both build folder. Just copy header file from this folder.
第 8 步:测试静态库
Step 8 : Test Static Library
创建新项目,将其命名为 TestLogger导入 libLogger.a
和头文件将头文件Logger.h
"导入任何你想使用的地方现在,使用这个 Logger 类作为默认做法.在我们的例子中,[Logger log:@"Test String"];在模拟器和设备中运行项目而已!!你有自己的静态库!!
Create New Project, name it TestLogger
Import libLogger.a
and header files
Import header file "Logger.h
" anywhere you want to use
Now, Use this Logger class as default practice.
In our case, [Logger log:@"Test String"];
Run Project in Simulator and Device both
That's it!! You have your own static Library!!
这篇关于如何创建静态库并且可以在 ios 的任何项目上仅添加 .a 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!