新建工程,点击下图中的加号:

选择Cocoa Touch Static Library:

点击next,起名字,点击finish后target栏会出现刚才新建的lib:

来到Xcode为我们自动创建好的头文件,如果不想要也可以删掉自己重新新建文件,写一个测试方法:

demoLib.h:
+ (void)printCurrentTime;
demoLib.m:
+ (void)printCurrentTime {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSLog(@"当前时间是:%@", [formatter stringFromDate:[NSDate date]]);
}
写好之后选择demoLib,点击Edit Scheme…:

选择run,把Build Configuration改成Release,因为这样Xcode会编译支持各个架构的静态库版本,否则只会编译支持当前架构的静态库版本:

点击close之后貌似不用手动run也不用手动build,Xcode已经自动为我们编译好了静态库,印象中以前是要手动build一下的来着:

点击Show In Finder查看,会有四个版本,分别是:
-
Debug-iphoneos
-
Debug-iphonesimulator
-
Release-iphoneos
-
Release-iphonesimulator
分别对应在Debug和Release下的模拟器和真机。
查看不同版本的静态库支持的架构,可以cd到对应的目录下,使用
lipo -info 静态库名称
指令,上述release版本支持的架构分别是 -
Release-iphoneos :armv7、arm64:
Release-iphoneos
-
Release-iphonesimulator:i386、x86_64
Release-iphonesimulator
接下来就是静态库合并了,你不可能发两个不同版本的静态库给人家用把,合并用到的指令是:lipo -create 静态库a 静态库b -output 合并后的静态库名称
:

这就是合并好的新的静态库:

可见合并后的静态库已经支持以上所有的架构了:

接下来,开开心心的新建一个文件夹,把合并后的静态库和include文件夹放进去,甩给同事用吧,微微一笑,深藏功与名。
如果有错误的地方,恳请指出,一起学习一起进步。
网友评论