使用cocoapod配置打包静态库及framework
安装cocoapods与cocoapods-packager
sudo gem install cocoapods -n /usr/local/bin
sudo gem install cocoapods-packager -n /usr/local/bin
使用pod生成库文件
pod package MyTest.podspec --force --no-mangle --configuration=Release
pod package MyTest.podspec --force --no-mangle --embedded --configuration=Release
使用xcode构建生成的库文件,Debug与Release需要合并库文件
lipo -create Release-iphoneos/MyTest/MyTest.framework/MyTest Release-iphonesimulator/MyTest/MyTest.framework/MyTest -output MyTest_SDK/MyTest.framework/MyTest
lipo -create ~/.../Products/Release-iphoneos/MyTest/MyTest.framework/MyTest ~/.../Products/Release-iphonesimulator/MyTest/MyTest.framework/MyTest -output /Users/luowei/Desktop/MyTest_SDK/MyTest.framework/MyTest
合并命令
rm -rf /Users/luowei/Projects/Projects_Test/MyTest/MyTest-1.5.0/ios/MyTest.framework
cp -rf /Users/luowei/Library/Developer/Xcode/DerivedData/MyTest-esmvdzoxkzgfquduflcqukmvksbc/Build/Products/Release-iphoneos/MyTest/MyTest.framework /Users/luowei/Projects/Projects_Test/MyTest/MyTest-1.5.0/ios/
lipo -create ~/.../Products/Release-iphoneos/MyTest/MyTest.framework/MyTest ~/.../Products/Release-iphonesimulator/MyTest/MyTest.framework/MyTest -output /Users/luowei/Projects/Projects_Test/MyTest/MyTest-1.5.0/ios/MyTest.framework/MyTest
使用pod package将原有的源码打包为静态库
pod package APodSpec.podspec --library
源码库的PodSpecs示例
Pod::Spec.new do |s|
s.name = 'MyTest'
s.version = '1.5.0'
s.summary = 'A short description of MyTest.'
s.description = <<-DESC
欢迎使用 MyTest SDK !
DESC
s.homepage = 'https://github.com/kooapp/MyTest'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'luowei' => 'luowei@wodedata.com' }
s.source = { :git => '/Users/luowei/Projects/Projects_Test/MyTest', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '9.0'
s.info_plist = {
'CFBundleIdentifier' => 'org.cocoapods.MyTest',
'NSMicrophoneUsageDescription' => '拍摄视频,请允许使用麦克风',
'NSCameraUsageDescription' => '上传照片,请允许访问您的相机',
'NSPhotoLibraryUsageDescription' => '上传照片,请允许访问您的相册',
'NSLocationUsageDescription' => '请允许访问您的位置',
'NSLocationWhenInUseUsageDescription' => '请允许访问您的位置',
}
s.source_files = [
'MyTest/Classes/**/*',
'MyTest/Libraries/DrawFace/*.{h,m}',
'MyTest/Libraries/DrawFace/UpLicense/**/*',
'MyTest/Libraries/UICKeyChainStore/*.{h,m}',
'MyTest/Libraries/PNUHud/*.{h,m}'
]
s.public_header_files = 'MyTest/Classes/MyTest.h'
s.resource_bundles = {
'MyTest' => ['MyTest/Assets/**/*']
}
# s.vendored_frameworks = 'MyTest/Libraries/TestTracker.framework'
# 'CommonCrypto',
s.frameworks = [
'Foundation','CoreGraphics','UIKit','CoreTelephony','CoreLocation','QuartzCore','ImageIO','SystemConfiguration','MobileCoreServices',
'VideoToolbox','Contacts','ContactsUI','AVFoundation','CoreMedia','CoreImage','AssetsLibrary','Photos','AudioToolbox'
]
s.libraries = 'bz2', 'z', 'iconv'
s.pod_target_xcconfig = { 'OTHER_LDFLAGS' => '$(inherited) -lObjC -lstdc++','ENABLE_BITCODE' => 'NO' }
s.vendored_libraries = 'MyTest/Libraries/DrawFace/libLFDrawFaceDetector.a'
s.resources = ['MyTest/Libraries/DrawFace/LinkfaceID.lic', 'MyTest/Libraries/DrawFace/lf_DrawFace_resource.bundle','MyTest/Libraries/DrawFace/btn_back@2x.png']
# s.static_framework = true
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
生成库的Pod配置示例
Pod::Spec.new do |s|
s.name = "MyTest"
s.version = "1.5.0"
s.summary = "A short description of MyTest."
s.license = {"type"=>"MIT", "file"=>"LICENSE"}
s.authors = {"luowei"=>"luowei@wodedata.com"}
s.homepage = "https://github.com/kooapp/MyTest"
s.description = "\u{6b22}\u{8fce}\u{4f7f}\u{7528} MyTest SDK !"
s.frameworks = ["Foundation", "CoreGraphics", "UIKit", "CoreTelephony", "CoreLocation", "QuartzCore", "ImageIO", "SystemConfiguration", "MobileCoreServices", "VideoToolbox", "Contacts", "ContactsUI", "AVFoundation", "CoreMedia", "CoreImage", "AssetsLibrary", "Photos", "AudioToolbox"]
s.libraries = ["bz2", "z", "iconv"]
s.source = { :path => '.' }
s.ios.deployment_target = '9.0'
s.ios.vendored_framework = 'ios/MyTest.framework'
end
构建脚本
# 指定打包的workspace文件
WORKSPACE='./Example/MyTest.xcworkspace'
# 指定打包的scheme
SCHEME='MyTest'
echo '================== Build Framework =================='
# 输出当前的构建目录
BUILD_DIR=`pwd`
echo ${BUILD_DIR}
# 设置导出framework路径
EXPORT_FRAMMEWORK_DIR='./product/'
# 设置真机打包的路径
DEVICE_DIR='../../build/Release-iphoneos/'
# 设置模拟器打包的路径
SIMULATOR_DIR='../../build/Release-iphonesimulator/'
xcodebuild -workspace ${WORKSPACE} -configuration Release -scheme ${SCHEME} -sdk iphoneos CONFIGURATION_BUILD_DIR=${DEVICE_DIR} clean build
xcodebuild -workspace ${WORKSPACE} -configuration Release -scheme ${SCHEME} -sdk iphonesimulator CONFIGURATION_BUILD_DIR=${SIMULATOR_DIR} clean build
# 删除旧有的framework文件夹,并重新创建
if [[ -d ${EXPORT_FRAMMEWORK_DIR} ]]; then
rm -rf ${EXPORT_FRAMMEWORK_DIR}
fi
mkdir -p ${EXPORT_FRAMMEWORK_DIR}
# 重置模拟器与真机的framework路径
DEVICE_DIR='./build/Release-iphoneos/'
SIMULATOR_DIR='./build/Release-iphonesimulator/'
# 拷贝真机framework到导出文件夹
cp -rf ${DEVICE_DIR} ${EXPORT_FRAMMEWORK_DIR}
# 合并真机与模拟器二进制文件
lipo -create ${DEVICE_DIR}/MyTest.framework/MyTest ${SIMULATOR_DIR}/MyTest.framework/MyTest -output ${EXPORT_FRAMMEWORK_DIR}/MyTest.framework/MyTest
echo '================== Build Finished =================='
echo 'Final Framework path:'
echo ${EXPORT_FRAMMEWORK_DIR}MyTest.framework
参考:
使用cocoapods插件打包静态库
创建公共/私有pod –podspec
使用cocoapods-packager打包静态库
使用CocoaPods开发lib库
组件化-动态库实战