iOS打包Framework傳Cocoapods

一直使用組內早期搭好的Jenkins+pod package自動打包流程。本次手動打包回顧知識。

  • XcodeAggregate打包Framework靜態庫傳Cocoapods.
  • Cocoapodspod package打包Framework.

一、Framework工程

1.創建Framework

2.添加文件

3.設置支持環境、Architectures、Mach-O Type

4.設置Public

到此Framework工程已創建好。


二、Aggregate打包靜態庫

1.創建Aggregate 添加Target生成

2.添加腳本

3.運行腳本生成Framework

4.Framework產物 (包含真機與模擬器)

生成Framework腳本

if [ "${ACTION}" = "build" ]
then
#要build的target名
target_Name=${PROJECT_NAME}
#build之后的文件夾路徑
build_DIR=${SRCROOT}/build
#真機build生成的framework文件路徑
DEVICE_DIR_Framework=${build_DIR}/Release-iphoneos/${PROJECT_NAME}.framework
#模擬器build生成的framework文件路徑
SIMULATOR_DIR_Framework=${build_DIR}/Release-iphonesimulator/${PROJECT_NAME}.framework
#目標文件夾路徑
INSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}
#判斷build文件夾是否存在,存在則刪除
if [ -d "${build_DIR}" ]
then
rm -rf "${build_DIR}"
fi
#判斷目標文件夾是否存在,存在則刪除該文件夾
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
#創建目標文件夾
mkdir -p "${INSTALL_DIR}"
#build之前clean一下
xcodebuild -target ${target_Name} clean
#真機build
xcodebuild -target ${target_Name} -configuration Release -sdk iphoneos
#模擬器build
xcodebuild -target ${target_Name} -configuration Release -sdk iphonesimulator
#復制頭文件到目標文件夾
cp -R "${DEVICE_DIR_Framework}" "${INSTALL_DIR}"
#合成模擬器和真機包
lipo -create "${DEVICE_DIR_Framework}/${PROJECT_NAME}" "${SIMULATOR_DIR_Framework}/${PROJECT_NAME}" -output "${INSTALL_DIR}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
#打開目標文件夾
open "${INSTALL_DIR}"

fi


運行腳本后會彈出Framework生成路徑文件夾。到此靜態庫已生成。


三、上傳Cocoapods

1.創建WxkNetKit.podspec文件

WxkKit git:(master) ? pod spec create WxkNetKit 
?  WxkKit git:(master) ? tree -L 1
.
├── Products
├── README.md
├── WxkNetKit
├── WxkNetKit.podspec
├── WxkNetKit.xcodeproj
├── WxkNetKitTests
└── build

2.編輯spec文件

Pod::Spec.new do |spec|
  spec.name         = "WxkNetKit"
  spec.version      = "0.0.1"
  spec.summary      = "WxkNetKit."
  spec.description  = <<-DESC
  WxkNetKit
                   DESC
  spec.homepage     = "https://github.com/wangxiaoKangK/WxkNetKit"
  spec.license      = { :type => "MIT", :file => "FILE_LICENSE" }
  spec.author             = { "gitWxk" => "15210111009@163.com" }
  spec.source       = { :git => "https://github.com/wangxiaoKangK/WxkNetKit.git", :tag => "#{spec.version}" }
  spec.platform = :ios, "9.0"
  spec.ios.deployment_target = "9.0"
  # spec.source_files  = "Classes", "Classes/**/*.{h,m}"
  # Framework
  # 我的文件路徑
  #   Products
  # │   └── WxkNetKit
  # │       └── WxkNetKit.framework
  spec.vendored_frameworks = "Products/**/*.{framework}"
end

3.打tag.

?  WxkKit git:(master) git tag 0.0.1
?  WxkKit git:(master) git push --tags
  1. 驗證spec文件
?  WxkKit git:(master) ? pod spec lint WxkNetKit.podspec --allow-warnings --verbose
pod spec lint xxx.podspec --verbose 
1.--verbose:打印錯誤詳情,當出現error的時候.
2.--use-libraries:當你的庫中有framework或.a文件,就加上吧。
3.--allow-warnings:有事有警告也有可能驗證不通過,可以加上這個。
  • 驗證通過

5.驗證成功后,推spec文件

發布:pod trunk push xxxxxx.podspec  --allow-warnings
?  WxkKit git:(master) ? pod trunk push WxkNetKit.podspec --allow-warnings
  • 成功發布

到此自己的靜態庫已經發布到Cocoapods。


驗證靜態庫


四、使用pod package打包Framework

正常配置好spec文件后 執行

pod peckage xxx.spec
# Overwrite existing files.
# 是否覆蓋已存在的文件
--force 
# Do not mangle symbols of depedendant Pods.
--no-mangle
# Generate embedded frameworks. 
# 生成靜態Framework
--embedded
# Generate static libraries.
# 生成靜態Library
--library
# Generate dynamic framework. 
# 生成動態Framework
--dynamic
# Bundle identifier for dynamic framework
# 動態Framework Bundle identifier
--bundle-identifier 
# Exclude symbols from dependencies.
# 不包含依賴的符號表,動態庫不能包含這個命令
--exclude-deps 
# Build the specified configuration (e.g. Debug). Defaults to Release
# 生成的庫是Debug還是Release,默認是Release。--configuration=Debug 
--configuration
# Only include the given subspecs
# 只給指定的子庫打包
--subspecs
# The sources to pull dependant pods from (defaults to https://github.com/CocoaPods/Specs.git)
# 存在私有依賴
--spec-sources=private,https://github.com/CocoaPods/Specs.git 

執行完會生成新文件夾,里面有WXKAAA.framework文件。

├── WXKAAA-0.0.1
│   ├── WXKAAA.podspec
│   ├── build
│   │   ├── Pods.build
│   │   │   └── Release-iphonesimulator
│   │   └── XCBuildData
│   │       ├── 45e4c79569ebe6fc185d9a8238a80c5a-desc.xcbuild
│   │       ├── 45e4c79569ebe6fc185d9a8238a80c5a-manifest.xcbuild
│   │       ├── BuildDescriptionCacheIndex-fca4d8b44dd9d4332eecf83387fccfa0
│   │       └── build.db
│   └── ios
│       └── WXKAAA.embeddedframework
│           ├── Resources
│           └── WXKAAA.framework

pod package 工具生成靜態包.framework完成。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。