0%

基于 CocoaPods 制作 iOS framework 并提交

前言

最近在写 SDK,由于依赖了第三方库,同时自己也要分发出去,所以总结下基于 CocoaPods 制作 framework 的问题。

SDK 依赖

首先是 SDK 的依赖情况:

sdk

IJKFramework 动态库依赖了 libssl.a 静态库,LiveSDK 动态库依赖了 CocoaPods 的公有库私有库、系统库和 IJKFramework。

项目结构

Demo 工程依赖 SDK Framework 工程

Demo

Demo

具体打包配置

由于 App Store 上架的时候不允许动态库嵌套,所以 LiveSDK 动态库内不能把 IJKFramework 动态库打进去(TODO:这里有点疑问,当时可能理解错了,后续需要 nm 命令来具体查看是否打包进去了)

Error

SDK Framework 工程配置

  1. Frameworks and Libraries 里添加 libssl.a 和系统库

  2. LinkingMach-O 里选择 Dynamic Library

SDK Podfile

1
2
3
4
5
6
7
8
platform :ios, '9.0'

target 'LiveSDK' do
use_frameworks!

pod 'AFNetworking', '4.0.1'
pod 'WebRTC', :git=>'https://github.com/WebRTC-IOS-SDK.git' , :tag => '2.1.11'
end

Build SDK framework,生成 Dynamic Framework

1
2
➜  file LiveSDK.framework/LiveSDK
LiveSDK.framework/LiveSDK: Mach-O 64-bit dynamically linked shared library arm64

制作私有 pod

Github 创建仓库 Live_iOS

Live_iOS
├─Live_iOS.podspec
├─Files
| ├─YDLiveSDK.framework
| ├─YDLIJKMediaFramework.framework

Live_iOS.podspec 内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Pod::Spec.new do |s|
s.name = "Live_iOS"
s.summary = "Live SDK for iOS."

s.homepage = "https://github.com/Live_iOS.git"

s.license = "MIT"

s.author = { "" => "" }
s.version = "1.0.0-beta3"
s.platform = :ios
s.platform = :ios, "9.0"

s.source = { :git => "https://github.com/Live_iOS.git", :tag => "#{s.version}" }

s.source_files = "Files/LiveSDK.framework/Headers/*.h"
# s.exclude_files = "Classes/Exclude"

s.public_header_files = "Files/LiveSDK.framework/Headers/*.h"

s.resources = "Files/LiveAuthMessage.plist"

s.vendored_frameworks = "Files/LiveSDK.framework", "Files/IJKMediaFramework.framework"

s.requires_arc = true

s.frameworks =
"UIKit", "OpenAL", "Accelerate", "ReplayKit", "AVFoundation", "WebKit",
"AudioToolbox", "CoreGraphics", "CoreMedia", "CoreVideo", "MediaPlayer",
"MobileCoreServices", "OpenGLES", "QuartzCore", "Foundation", "VideoToolbox"

s.libraries = "sqlite3", "resolv", "c++", "z", "bz2"

s.dependency 'AFNetworking', '4.0.1'

end

提交到 CocoaPods 官方仓库 Live_iOS

项目集成

项目集成有两种方式。先大体说明,后面有具体代码。但是两种情况都不需要添加系统依赖库就可以运行,这里存疑???

第一种用户集成简单,使用 cocodpods 完成所有工作,但是需要我们制作 pod 源,因为 WebRTC 现在是私有 pod。如果用户把我们的 SDK 在他们项目的 submodule 里使用的话也使用这种,原因是因为现在 CocoaPods 1.10.0 不支持在 podspec 里写 :git=>'https://github.com/WebRTC-IOS-SDK.git' , :tag => '2.1.11'

第二种就是正常的接入,用户做的工作会多一点。

第一种

需要先制作 pod 源然后再集成

  1. Github 创建仓库做为 pod 源,git 地址为 https://github.com/Live_iOS_Dependency.git

    仓库需要创建 WebRTC/2.1.1,然后在版本号文件夹里创建 WebRTC.podspec, 内容和私有的 WebRTC.podspec 一致。

  2. 编辑 demo 的 podfile

1
2
3
4
5
6
7
8
9
10
source 'https://github.com/CocoaPods/Specs.git'
# 这里要添加源
source 'https://github.com/Live_iOS_Dependency.git'
target 'test'do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for test
pod 'Live_iOS', '1.0.0-beta3'
pod 'WebRTC', '2.1.11'
end
  1. Done

第二种

  1. 编辑 demo 的 podfile

    1
    2
    3
    4
    5
    6
    7
    target 'test'do
    # Comment the next line if you don't want to use dynamic frameworks
    use_frameworks!
    # Pods for test
    pod 'AFNetworking', '4.0.1'
    pod 'WebRTC', :git=>'https://github.com/WebRTC-IOS-SDK.git' , :tag => '2.1.11'
    end
  2. Live_iOS.frameworkIJKMediaFramework.framework 拖进项目里,并根据命令 filecodesign -dv 的结果在 Project - General - Frameworks, Libraries and Embedded Content 里正确配置。

  3. Done