SDK 开发 .a .framework .bundle (xcode引用) 依赖sdk工程

一. 静态库.a

1.创建静态库工程 Cocoa Touch Static Libray  ,然后可以创建一个测试视图 TestView

2.暴露头文件 -> Build Phases--> 点左上角+ 加号-> New Header Phase  ,此时下面多了一个行 Headers 文件 ,将需要暴露的头文件拖到 public 中

3. 编译 command+B 后, .a 文件由红色变黑色, 说明编译成功, show in Finder 在文件夹中找到 .a 及头文件

 二.静态库. framework (= .a + .h + 资源文件)

更改参数: Build Setting

a. 搜 Linking-->(1)Dead Code Stripping 改为 NO   (2)Mach-O Type 改为 Static Library 

b. 在Architectures下增加armv7s,并选中。将Build Active Architecture Only 设置为NO。

c. 公开头文件Headers

 

1.使用Aggregate方式, 支持多平台

 http://blog.csdn.net/tianshats/article/details/52045974

2.使用终端, 合并 模拟器 和 真机 为一个版本

http://www.jianshu.com/p/87dbf57cfe4a  (包含了两种方法)

打开控制台输入
lipo -create
iphoneos下frameworkTest的路径 (空格)simulator下frameworkTest的路径(.framework下一级白色的那个文件)
-output 新的路径,
这样就完成了模拟器和真机版本的合并,新路径下的frameworkTest就是你合并后的文件,将这个文件名字改成和你未合并之前的Test一样的名字,放到framework文件夹下,替换掉原来的frameworkTest文件。
完成后:

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't move temporary file: /Users/maxueshan/Desktop/frame to file: /Users/maxueshan/Desktop/frame.lipo (Is a directory)


这里我们合并的时候会遇到一个error,这是啥原因还真不知道,但是会在和我们-output的文件夹路径并列的地方生成一个 .lipo文件 

我们的操作是按照人家说的把合成后的文件名字改成MyFrameworkTest替换原来的(.framework中的白色文件)。而且,把后缀.lipo去掉!

 

 

 

 

三. 包文件Bundle (资源文件包) 

http://blog.csdn.net/tianshats/article/details/52045974

1.  创建包工程: macOS -> Bundle ->将资源拖入工程中, common+B 编译即可--> show in Finder

2. 资源包只需要编译,不需要安装: target-> Build Setting -> 搜索 install ->(1) skip install 改为Yes  (2)installation Directory 删除安装路径

3.如何使用包文件

(1) 图片:  拼接路径

 imageV.image = [UIImage imageNamed:@"XSBundle.bundle/Contents/Resources/2.png"];

(2)图片: 拼接包路径

 NSString *bundlePath = [[NSBundle mainBundle]pathForResource:@"XSBundle" ofType:@"bundle"];

    

 NSString *imagePath = [bundlePath stringByAppendingPathComponent:@"Contents/Resources/2.png"];

 

imageV.image = [UIImage imageWithContentsOfFile:imagePath];

 

//封装成方法

#pragma mark : - 资源相关

-(UIImage *)getImage:(NSString *)name{

    NSBundle *currentBundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[TGRefreshOC class]] pathForResource:@"TGRefreshOC" ofType:@"bundle"]];

    UIImage *img =  [UIImage imageWithContentsOfFile:[currentBundle pathForResource:name ofType:@"png"]];

    return img;

}

 

 

(3)xib 

NSString * bundlePath = [[ NSBundle mainBundle] pathForResource: @ "MyBundle" ofType :@ "bundle"];

    NSBundle *resourceBundle = [NSBundle bundleWithPath:bundlePath];

    UIViewController *vc = [[UIViewController alloc] initWithNibName:@"vc_name" bundle:resourceBundle];

 

 

 

 

 

参考链接整理:

1. xcode 项目引入另一个xcode工程

http://blog.csdn.net/liufangbaishi2014/article/details/50057485

步骤:

a.将你的SDK**工程文件夹拷贝到textSDK 的工程根目录下, 将. xcodeproj蓝色文件 add file...到当前工程目录中

b. Build Phase --> Target Dependencies  --> 点击+ 添加库文件

c.Build Phase  --> Link binary with Libraries--> 点击+ 添加库文件

d.Build Setting -->Search Paths->Header Search Paths中添加上SDK**对应的目录$(SRCROOT)/SDK/SDK就不报错了     最后面设置成 recursive

 

2.sdk 开发(.a 创建 .framework .bundle 以及脚本运行支持多平台)

http://www.jianshu.com/p/c131baae4307

 

3.引用. framework 时候遇到的错误

错误一:

dyld: Library not loaded: @rpath/GOPayFramework.framework/GOPayFramework

  Referenced from: /var/containers/Bundle/Application/3E41EEDC-2800-4687-A863-04BB9352508A/TestFramework.app/TestFramework

  Reason: image not found

解决办法: Build phase-> copy file -> 改成 framework ,并添加需要的.framework

 

http://blog.csdn.net/zzzzzdddddxxxxx/article/details/50495659

 

 4.查看.framework 所支持的平台

为了检查一下我们的多平台编译真的成功了,启动终端,导航到桌面上的framework,像下面一样:

$ cd ~/Desktop/MySDK.framework

$  xcrun lipo -info MySDK

 

 

 

posted @ 2017-07-21 10:59  Da雪山  阅读(676)  评论(0编辑  收藏  举报