一、FrameWork创建

二、修改配置文件
2.1:Build active Architecture Only设置为NO
- YES:只会选择编译、链接对应目标设备的指令集。
- NO:编译、链接会涵盖所有指令集,必要时选择执行对应的指令集。
- Debug一般设置为YES,执行效率高。
- Release一般为NO,以支持所有可能的架构。
指令集
模拟器:4s ~ 5 : i386; 5s以后 : x86_64。
真机:
- armv6:iPhone1、2、3G;iPod Touch1、2
- armv7设备:iPhone 3GS、 4、4S;iPad1、2,iPod Touch 3G、 4
- armv7s设备:iPhone 5、5C,iPad4
- arm64设备:iPhone 5S以后、iPad Air以后
- 指令集向下兼容 armv7s >> armv7 >> armv6 【iPhone5可以跑armv7架构的指令集】
请参照下图设置

2.2:Dead Code Stripping 为NO是编译选项优化,包瘦身
请参照下图设置

2.3:设置framework最低支持的版本
请参照下图设置

三、创建文件并配置
3.1:创建文件


3.2:引入Test.h此处引入必须用<>

3.3:在Build Phases里配置文件公开

四、创建测试Demo



点击运行报错修改
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_Test", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

再次运行打印

四、引入cocoaPods 类库
4.2:创建Podfile文件

4.2:在Podfile文件内添加类库

4.2.1:如果保存就修改只引入FrameWork target下面的库 FrameWorkDemo下面的库不引入了下面我换了一个弹框的库SVProgressHUD 因为我这里在4.2那一步报错了所以就改成了这个

4.3:在终端执行pod install

再次运行项目

修改Test文件下的内容

再次运行FrameWorkDemo看到

五、合并模拟器和真机的FrameWork
5.1:点击查看本地已经生成的FrameWork


5.2:生成Release环境下的FrameWork




5.1:再次点击查看本地已经生成的FrameWork

六:真机版本和模拟器版本framework合并
6.1 查看架构
打开终端使用命令行 lipo -info 查看framework架构信息
真机版本


6.2合并真机模拟器版本
因为以上获取的framework只能在对应的版本上运行(即真机只能在设备上运行模拟器版本只能在模拟器上面运行使用)所以需要合并为通用版本
命令行语句:sudo lipo -create (此处请填写真机HJFrameWork文件路径) (此处填写模拟器HJFrameWork文件路径) -output 自定义合成文件存储路径(合成文件的名字HJFrameWork)



最后新建一个项目导入FrameWork就可以使用了但是需要注意的是一定要记得在这个地方引入

后期错误处理
Libtool /Users/hanxiaojie/Library/Developer/Xcode/DerivedData/YDFramework-ahinrorgjyathifamwkiivgvdftt/Build/Intermediates.noindex/YDFramework.build/Debug-iphonesimulator/YDFramework.build/Objects-normal/x86_64/YDFramework normal x86_64 (in target: YDFramework)
cd /Users/hanxiaojie/Documents/YDFramework
export IPHONEOS_DEPLOYMENT_TARGET=9.0
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -D -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.2.sdk -L/Users/hanxiaojie/Library/Developer/Xcode/DerivedData/YDFramework-ahinrorgjyathifamwkiivgvdftt/Build/Products/Debug-iphonesimulator -filelist /Users/hanxiaojie/Library/Developer/Xcode/DerivedData/YDFramework-ahinrorgjyathifamwkiivgvdftt/Build/Intermediates.noindex/YDFramework.build/Debug-iphonesimulator/YDFramework.build/Objects-normal/x86_64/YDFramework.LinkFileList -lPods-YDFramework -o /Users/hanxiaojie/Library/Developer/Xcode/DerivedData/YDFramework-ahinrorgjyathifamwkiivgvdftt/Build/Intermediates.noindex/YDFramework.build/Debug-iphonesimulator/YDFramework.build/Objects-normal/x86_64/YDFramework
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lPods-YDFramework
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lPods-YDFramework is not an object file (not allowed in a library)
Command Libtool failed with a nonzero exit code
Showing Recent Messages
/error:-1: can't locate file for: -lPods-YDFramework
Showing Recent Messages
/error:-1: file: -lPods-YDFramework is not an object file (not allowed in a library)
Showing Recent Messages
Command Libtool failed with a nonzero exit code
以上错误由于选择的是dedug模式引起的,改为Release就好了



网友评论