1.新建Cocoa Touch Static Library工程
选择静态库工程点击下一步

2.生成的静态库工程

3.把封装好的核心代码拖进工程

4.制作debug版本的.a文件,release版本的流程一样

4.1 关闭只编译活跃的系统架构,关闭之后就相当于,在模拟器情况下.a编译成i386和x86_64,真机情况下.a编译成armv7和arm64,这样.a运行到哪个型号的手机上都可以支持
模拟器CPU架构:
iPhone 4s-5: i386
iPhone 5s-6s Plus: x86_64
真机的CPU架构:
armv6: iPhone、iPhone 2、iPhone 3G、iPod Touch(第一代)、iPod Touch(第二代)
armv7: iPhone 3Gs、iPhone 4、iPhone 4s、iPad、iPad 2
armv7s: iPhone 5、iPhone 5c
arm64: iPhone 5s、iPhone 6、iPhone 6 Plus、iPhone 6s、iPhone 6s Plus、iPad Air、iPad Air2、iPad mini2、iPad mini3
注* armv7兼容armv7s

4.2 选取支持的最低系统

4.3 把.h文件添加进工程,目的是把封装好的库的接口暴露出来,把Subpath的路径清空,不然生成的.h和.a不在同一目录下

4.4 点击运行,Product下 的.a由红色变黑

4.5 Product->libCreatLip.a,右键show in FinderFin会找到生成的.a和.h文件

4.6生成的.a和.h就可以拖进工程使用,如果想看.a支持的架构,可以打开终端,输入命令 lipo -info查看,下图信息显示.a支持i386和x86_64

4.7 生成真机的.a文件,选择真机模式,其它流程与模拟器流程一样

真机支持armv7和arm64

4.8 模拟器生成的.a和真机生成的.a合并,这样把生成好的静态库在模拟器和真机模式下都能使用,使用到的命令: lipo -create 模拟器的.a地址 真机的.a地址 -output bingLip.a

网友评论