整体架构为:宿主 << 中间组件库 << 子组件库,其中子组件库内置于中间组件库classes目录中,且只有中间组件库有podspec,子组件库没有podspec只有各自的源码文件夹。
改造过程中有一个需求:独立出去的子组件,均要以源码的形式导入到宿主工程,不能影响正常开发流程。
宿主工程的podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '14.0'
inhibit_all_warnings!
use_modular_headers!
use_frameworks! # :linkage => :static
source 'https://github.com/CocoaPods/Specs.git'
source 'http://gitlab.test.com/kernel/ios/cocoapods/specs'
# 添加其他源
def app_pods
pod 'YYCache'
pod 'YYText'
pod 'YYModel'
pod 'YYCategories'
pod 'AFNetworking'
pod 'Masonry'
# WebImage
pod 'SDWebImage'
pod 'SDWebImageSwiftUI'
pod 'SDWebImageWebPCoder'
pod 'MBProgressHUD',:git => 'https://github.com/jdg/MBProgressHUD.git', :commit => '18c442d57398cee5ef57f852df10fc5ff65f0763'
pod 'ffmpeg-kit-ios-full-gpl', '~> 6.0'
# pod 'SnapSDK', :subspecs => ['SCSDKCreativeKit']
# pod 'HXLog', '1.2.0'
# dokit
pod 'DoraemonKit/Core', :configurations => ['Debug']
# Swift 相关 ----
pod 'Then'
# CombineExt
pod 'CombineExt'
# 约束布局
pod 'SnapKit'
# 弹框 吐司
pod 'AlertToast'
# 网络组件 Swift
pod 'Alamofire', '~> 5.8'
# 网络组件, 依赖 Alamofire
pod 'Moya/Combine'
# JSON
pod 'SwiftyJSON'
# 加密
pod 'CryptoSwift'
# swift数据库
# pod 'RealmSwift'
pod 'WCDB.swift'
# 云存储
pod 'AWSS3'
# lottie
pod 'lottie-ios'
# log
pod 'CocoaLumberjack/Swift'
# HTML解析
pod 'SwiftSoup', '~> 2.7.0'
end
def inner_pods
pod 'HXELKLog', :git => 'http://gitlab.test.com/kernel/ios/hxelklog.git'
pod 'HXPAGVideoLab', :git => 'http://gitlab.test.com/10jqka/air/phone_assistant/hxpagvideolab.git', :branch => 'main'
pod 'HXDetectSDK', :git => 'http://gitlab.test.com/heqikai/facedetection.git', :tag => '1.8.2'
pod 'HXNativeWebEngine', :git => 'http://gitlab.test.com/kernel/ios/hxnativewebengine.git', :branch => 'work-df', :subspecs => ['Standard', 'webInterceptor']
pod 'DreamPhotoSubmodule/CommonUI', :path => '../DreamPhotoSubmodule/' # :git => "http://gitlab.test.com/10jqka/air/phone_assistant/dfiosmodule.git", :branch => "main"
pod 'DreamPhotoSubmodule/ThirdService', :path => '../DreamPhotoSubmodule/'
pod 'DreamPhotoSubmodule/HXService', :path => '../DreamPhotoSubmodule/'
end
target 'HXDreamPhoto' do
app_pods
inner_pods
end
# 推送扩展
def push_pods
# 用了收到消息解析失败.....
pod 'FirebaseMessaging'
pod 'GoogleUtilities'
end
target :HXDreamPhotoPush do
push_pods
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'] = 'YES'
config.build_settings['CLANG_WARN_UNGUARDED_AVAILABILITY'] = 'NO'
# 去除BITCODE、跳过pod签名
config.build_settings['ENABLE_BITCODE']='NO'
config.build_settings['EXPANDED_CODE_SIGN_IDENTITY']=""
config.build_settings['CODE_SIGNING_REQUIRED']="NO"
config.build_settings['CODE_SIGNING_ALLOWED']="NO"
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"]=""
end
end
end
#post_install do |installer|
# # installer.pods_project.targets.each do |target|
# # target.build_configurations.each do |config|
# # config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
# # config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES'
# # config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
# # end
# # end
#end
中间组件所在Example工程的podfile:
use_frameworks!
platform :ios, '14.0'
source 'https://github.com/CocoaPods/Specs.git'
source 'http://gitlab.test.com/ios_third_party_libs/Communism'
source 'http://gitlab.test.com/kernel/ios/cocoapods/specs'
source 'http://gitlab.test.com/ios_arsenal/cocoapods/specs'
target 'DreamPhotoSubmodule_Example' do
pod 'DreamPhotoSubmodule/HXService', :path => '../'
pod 'DreamPhotoSubmodule/CommonUI', :path => '../'
pod 'DreamPhotoSubmodule/ThirdService', :path => '../'
pod 'HXThemeSkin', :git => 'http://gitlab.test.com/kernel/ios/hxthemeskin.git', :branch => 'work-xmw-20230301-theme-skin'
pod 'LEETheme', :git => 'http://gitlab.test.com/ios_third_party_libs/leetheme.git'
pod 'HXAPMonitor', :git => 'http://gitlab.test.com/kernel/ios/apm-monitor-ios.git', :commit => 'e63145e'
pod 'HXPAGVideoLab', :git => 'http://gitlab.test.com/10jqka/air/phone_assistant/hxpagvideolab.git', :branch => 'main'
target 'DreamPhotoSubmodule_Tests' do
inherit! :search_paths
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'] = 'YES'
config.build_settings['CLANG_WARN_UNGUARDED_AVAILABILITY'] = 'NO'
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"]=""
end
end
end
中间组件的podspec:
#
# Be sure to run `pod lib lint DreamPhotoSubmodule.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'DreamPhotoSubmodule'
s.version = '0.1.0'
s.summary = 'DreamPhoto 项目子模块.'
# 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 = <<-DESC
初版, UI、Service等子模块
DESC
s.homepage = 'http://gitlab.test.com/10jqka/air/phone_assistant/dfiosmodule'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'sdffdfs' => 'sdfdfs@test.com' }
s.source = { :git => 'http://gitlab.test.com/10jqka/air/phone_assistant/dfiosmodule.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '14.0'
# s.source_files = 'DreamPhotoSubmodule/Classes/**/*'
# s.resource_bundles = {
# 'DreamPhotoSubmodule' => ['DreamPhotoSubmodule/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
s.static_framework = true
s.swift_version = '5.8'
s.default_subspec = 'Core'
s.subspec "Core" do |ss|
ss.source_files = 'DreamPhotoSubmodule/Classes/Core/**/*'
ss.dependency 'Then'
end
s.subspec "HXService" do |ss|
ss.source_files = ['DreamPhotoSubmodule/Classes/HXService/**/*', 'DreamPhotoSubmodule/Classes/*.{h,m,swift}']
ss.dependency 'SSZipArchive'
ss.dependency 'HXThemeSkin'
ss.dependency 'LEETheme'
# s.pod_target_xcconfig = {
# 'SWIFT_OBJC_INTERFACE_HEADER_NAME' => 'DreamPhotoSubmodule-Swift.h',
# 'SWIFT_OBJC_BRIDGING_HEADER' => '$(PODS_TARGET_SRCROOT)/DreamPhotoSubmodule/Classes/DreamPhotoSubmodule-Bridging-Header.h'
# }
end
s.subspec "ThirdService" do |ss|
ss.source_files = 'DreamPhotoSubmodule/Classes/ThirdService/**/*'
s.dependency 'HXAPMonitor'
s.dependency 'SDWebImage'
s.dependency 'CocoaLumberjack/Swift'
s.dependency 'SSZipArchive'
s.dependency 'TikTokOpenSDK'
s.dependency 'HXPAGVideoLab'
s.dependency 'libpag'
s.dependency 'ReactiveObjC'
end
s.subspec "CommonUI" do |ss|
ss.source_files = 'DreamPhotoSubmodule/Classes/CommonUI/**/*'
s.frameworks = 'UIKit', 'Combine'
ss.dependency 'DreamPhotoSubmodule/Core'
ss.dependency 'SnapKit'
ss.dependency 'SDWebImage'
ss.dependency 'SDCycleScrollView'
ss.dependency 'lottie-ios'
ss.dependency 'SwiftyJSON'
ss.dependency 'WCDB.swift'
ss.dependency 'CombineExt'
end
end
分别执行过 pod install 后的中间组件 Example 工程的pods目录,宿主工程的pods目录:
问题:如何让独立出去的子组件,在源码和framework两种形式上自由切换?我还不太明白。
网友评论