Xcode framework 的编译及测试

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kmyhy/article/details/82991408

创建 Framework 工程

  1. 新建 Cocoa Touch Framework
  2. 编写 Podfile
  3. pod install 安装第三方依赖
  4. 打开 .xcworkspace
  5. 添加要公开的头文件到 Build Phases / Headers / Public 下
  6. command+B,编译 framework

创建测试工程

  1. 在静态库的工作空间中,新建一个 Target,选择 Single view applictation,作为测试工程
  2. 选择这个 Target,在 Build Phases 中,在 Target Dependencies 下添加已经编译好的 framework 作为依赖
  3. 在测试工程的 General / Linked Frameworks and Librarys 中添加这个 framework
  4. 在测试工程中编写调用代码,进行调试

常见错误:

  • dyld: Library not loaded: @rpath……Reason: image not found

将 framework 改为静态库,mach-o type 设为 Static Library,然后重新编译 framework

  • 编译错误:找不到第三方 cocoapods 库的头文件

    修改 Podfile 文件,在测试工程的 target 下增加必要的 pod。

如果 framework 和测试工程的 pod 相同,也可以用 .each 循环:

targets = ['YLYIndoorNavigation','YLYIndoorNavigationDemo']
targets.each do |t|
    
    target t do
        pod 'AFNetworking'
        pod 'FDFullscreenPopGesture', '~> 1.1'
		... ...
    end

end

然后 pod install。

  • 编译出错:Undefined symbols for architecture i386:

    “___gxx_personality_v0”, referenced from:

    在工程中添加添加 libstdc++.dylib 即可。

  • Archive 时报错:ld: library not found for -lAFNetworking

    在 Link Binary with Libraries 中,添加相关 pod 库(比如libAFNetworking.a 等)。

  • Archive 出错:bitcode bundle could not be generated because ‘xxxx’ was built without full bitcode.

    将 Target 的 Enable Bitcode 设置为 NO。

猜你喜欢

转载自blog.csdn.net/kmyhy/article/details/82991408