使用元件化也有一段時間了,碰到不少問題,但也算是給解決了,總結一下手動引入第三方元件的一些問題,個人是用Swift,OC的解決方式就沒有實踐過。.podspec 中以 subspec 的方式 為主,主要包含微信、支付寶、微網誌、極光推送、友盟這幾種
微信
微信需要引入 .a 和 .h 檔案
.h檔案使用 source_files
.a檔案使用vendored_libraries
原目錄如下
Pod::Spec.new do |s| s.name = 'xxx-BaseCore' s.version = '1.0.7' s.summary = '基礎元件'# This description is used to generate tags and improve search results.# * Think: What does it do? Why did you write it? What is the focus?# * Try to keep it short, snappy and to the point.# * Write the description between the DESC delimiters below.# * Finally, don't worry about the indent, CocoaPods strips it! s.description = < 'MIT', :file => 'LICENSE' } s.author = { '[email protected]' => '[email protected]' } s.source = { :git => '[email protected]', :tag => s.version.to_s } s.ios.deployment_target = '11.0' s.swift_version = '5.0' s.source_files = 'xxx-BaseCore/Classes/**/*' s.default_subspec = "Core" s.resource_bundles = { 'xxx-BaseCore' => [ 'xxx-BaseCore/Assets/*{.storyboard,.xcassets}', 'xxx-BaseCore/Assets/**/*'] } s.static_framework = true s.frameworks = 'UIKit' # 核心子產品 s.subspec 'Core' do |subspec| subspec.dependency 'RxSwift' , '4.5.0' subspec.dependency 'RxGesture' , '2.2.0' subspec.dependency 'RxDataSources' , '3.1.0' subspec.dependency 'Moya/RxSwift' , '13.0' subspec.dependency 'ObjectMapper' , '3.4.2' end # 微信子產品 s.subspec 'WXManager' do |subspec| subspec.dependency 'xxx-BaseCore/Core' subspec.frameworks = 'CFNetwork', 'CoreMotion', 'Foundation', 'CoreGraphics', 'SystemConfiguration', 'UIKit', 'CoreText', 'QuartzCore', 'CoreTelephony' subspec.libraries = 'z', 'sqlite3.0', 'c++' subspec.source_files = 'xxx-BaseCore/WXManager/*.h' subspec.vendored_libraries = 'xxx-BaseCore/WXManager/libWeChatSDK.a' endend
支付寶
支付寶需要引入 .framework 和 .h 檔案
目錄與微信一緻
.framework檔案使用 vendored_frameworks
.h檔案使用source_files 需要注意的是要将framework中的.h檔案都引入
# 支付寶子產品 s.subspec 'AliPayManager' do |subspec| subspec.dependency 'xxx-BaseCore/Core' subspec.frameworks = 'CFNetwork', 'CoreMotion', 'Foundation', 'CoreGraphics', 'SystemConfiguration', 'UIKit', 'CoreText', 'QuartzCore', 'CoreTelephony' subspec.libraries = 'z', 'sqlite3.0', 'c++' subspec.source_files = 'xxx-BaseCore/AliPayManager/*','xxx-BaseCore/AliPayManager/AlipaySDK.framework/Headers/*.h' subspec.vendored_frameworks = 'xxx-BaseCore/AliPayManager/AlipaySDK.framework' subspec.resources = ['xxx-BaseCore/AliPayManager/AlipaySDK.bundle'] end
微網誌
與微信基本一緻,但要注意的是需要添加資源檔案
# 微網誌子產品 s.subspec 'WeiboManager' do |subspec| subspec.dependency 'xxx-BaseCore/Core' subspec.frameworks = 'CFNetwork', 'CoreMotion', 'Foundation', 'CoreGraphics', 'SystemConfiguration', 'UIKit', 'CoreText', 'QuartzCore', 'CoreTelephony' subspec.libraries = 'z', 'sqlite3.0', 'c++' subspec.source_files = 'xxx-BaseCore/WeiboManager/*.h' subspec.vendored_libraries = 'xxx-BaseCore/WeiboManager/libWeiboSDK.a' subspec.resources = ['xxx-BaseCore/WeiboManager/WeiboSDK.bundle'] end
極光
與微信基本一緻,但要住要的是需要添加資源檔案
官網下載下傳的.a檔案命名可能不規範需要改一下名字
# 極光推送子產品 s.subspec 'JPush' do |subspec| subspec.dependency 'xxx-BaseCore/Core' subspec.frameworks = 'CFNetwork', 'CoreFoundation', 'CoreTelephony', 'SystemConfiguration', 'CoreGraphics', 'Foundation', 'UIKit', 'Security', 'UserNotifications' subspec.libraries = 'z','resolv' subspec.source_files = 'xxx-BaseCore/JPush/*.h' subspec.vendored_libraries = 'xxx-BaseCore/JPush/libjcore-noidfa-ios-2.1.4.a','xxx-xxx/JPush/libjpush-extension-ios-1.1.2.a','xxx-BaseCore/JPush/libjpush-ios-3.2.6.a' end
友盟
友盟的情況比較特殊,主要是swift內建時有一些麻煩,找了不少資料才将其搞定
目錄結構
簡單的說就是增加prepare_command 為swift建立modulemap
我這邊內建的是友盟的facebook和微信
s.prepare_command = < xxx/Umeng/UMCommon.framework/Modules/module.modulemap framework module UMCommon { umbrella header "UMCommon.h" export * link "sqlite3.0" } EOF # 建立UMShare Module rm -rf xxx/Umeng/UMShare.framework/Modules mkdir xxx/Umeng/UMShare.framework/Modules touch xxx/Umeng/UMShare.framework/Modules/module.modulemap cat < xxx/Umeng/UMShare.framework/Modules/module.modulemap framework module UMShare { umbrella header "UMShare.h" export * link "sqlite3.0" } EOF EOF
子子產品内容
# 友盟 s.subspec 'Umeng' do |subspec| subspec.dependency 'xxx/Core' subspec.frameworks = 'CFNetwork', 'CoreMotion', 'Foundation', 'CoreGraphics', 'SystemConfiguration', 'UIKit', 'CoreText', 'QuartzCore', 'CoreTelephony', 'WebKit' subspec.libraries = 'z', 'sqlite3.0', 'c++' subspec.resources = [ 'xxx/Umeng/UMSocialSDKResources.bundle' ] subspec.source_files = 'xxx/Umeng/*' subspec.vendored_frameworks = [ 'xxx/Umeng/*.framework', 'xxx/Umeng/SocialLibraries/Facebook/*.framework' ] subspec.vendored_libraries = [ 'xxx/Umeng/SocialLibraries/Facebook/libSocialFacebook.a', 'xxx/Umeng/SocialLibraries/WeChat/libSocialWeChat.a' ] end