一直使用組內(nèi)早期搭好的
Jenkins
+pod package
自動打包流程。本次手動打包回顧知識。
-
Xcode的
Aggregate
打包Framework
靜態(tài)庫傳Cocoapods
. -
Cocoapods的
pod package
打包Framework
.
一、Framework工程
1.創(chuàng)建Framework
2.添加文件
3.設置支持環(huán)境、Architectures、Mach-O Type
4.設置Public
到此Framework工程已創(chuàng)建好。
二、Aggregate打包靜態(tài)庫
1.創(chuàng)建Aggregate 添加Target生成
2.添加腳本
3.運行腳本生成Framework
4.Framework產(chǎn)物 (包含真機與模擬器)
生成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
#創(chuàng)建目標文件夾
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
生成路徑文件夾。到此靜態(tài)庫已生成。
三、上傳Cocoapods
1.創(chuàng)建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
- 驗證
spec
文件
? WxkKit git:(master) ? pod spec lint WxkNetKit.podspec --allow-warnings --verbose
pod spec lint xxx.podspec --verbose
1.--verbose:打印錯誤詳情,當出現(xiàn)error的時候.
2.--use-libraries:當你的庫中有framework或.a文件,就加上吧。
3.--allow-warnings:有事有警告也有可能驗證不通過,可以加上這個。
- 驗證通過
5.驗證成功后,推spec
文件
發(fā)布:pod trunk push xxxxxx.podspec --allow-warnings
? WxkKit git:(master) ? pod trunk push WxkNetKit.podspec --allow-warnings
- 成功發(fā)布
到此自己的靜態(tài)庫已經(jīng)發(fā)布到Cocoapods。
驗證靜態(tài)庫
四、使用pod package
打包Framework
正常配置好spec
文件后 執(zhí)行
pod peckage xxx.spec
# Overwrite existing files.
# 是否覆蓋已存在的文件
--force
# Do not mangle symbols of depedendant Pods.
--no-mangle
# Generate embedded frameworks.
# 生成靜態(tài)Framework
--embedded
# Generate static libraries.
# 生成靜態(tài)Library
--library
# Generate dynamic framework.
# 生成動態(tài)Framework
--dynamic
# Bundle identifier for dynamic framework
# 動態(tài)Framework Bundle identifier
--bundle-identifier
# Exclude symbols from dependencies.
# 不包含依賴的符號表,動態(tài)庫不能包含這個命令
--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
執(zhí)行完會生成新文件夾,里面有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
工具生成靜態(tài)包.framework
完成。