组件化拆分

235 阅读4分钟

组件化细节****

组件化打包上架解决报错

Asset validation failed

Invalid Bundle Executable. The executable file 'NewAudio.app/Frameworks/ZipZap.framework/ZipZap' contains incomplete bitcode. To compile binaries with complete bitcode, open Xcode and choose Archive in the Product menu. (ID: 3ab8743d-497b-48a1-b74a-b643d0532492)

  


otool -l ZipZap | grep __LLVM | wc -l

  


xcrun bitcode_strip -r ZipZap -o ZipZap

 

1、如何拆分图片资源

图片放入bundle资源

2、如何管理 组件

多以git管理方式,cocoaPods引入

3、 具体项目结构,该如何划分

基础库是存放网络封装类,工具类,分类,数据库,会员功能、播放器模块

基础库命名: DHFBaseLib

蓝牙库是对蓝牙功能及自定义指令集的封装

杰理蓝牙库命名: DHFBluetoothLib

自定义的蓝牙库命名: DHFCustomBluetoothLib

业务模块如何拆分

业务功能主要有:登录注册,首页,个人中心,AI,白噪音,弹窗,转写翻译

 

细分 方案:单独组件化,每个模块能独立于主工程进行编译******

 

单独组件命名:

DHFCommonModule:  通用功能:权限设置,主题切换,语言切换,帮助反馈,检查更新,关于,联系我们, 登录、注册功能:游客登录,第三方登录(微信,Apple),需依赖微信登录SDK,白噪音功能,弹窗模块,工具模块,小组件模块,广告,依赖友盟,阿里SDK(壳子配置key初始化)

 

DHFHomeModule: 设备功能:连接,扫描,导航,天气,连接后的功能,参数需要通过基础库转出去,基类控制转发数据;

 

DHFAITranslateModule:  转写翻译及AI功能:AI相关:对话,AIMusic

,需依赖第三方库,讯飞,小凡SDK;

 

组件化完成后,创建只包含翻译功能新项目

1、创建项目,修改项目命名,包名,导入图片资源

2、初始化配置:讯飞AIUI、友盟、微信、阿里、阿里推送、阿里oss、PayPal、谷歌地图、高度地图,隐私政策地址;

3、导入翻译功能组件,pod导入

   pod  DHFBaseLib

   pod  DHFAITranslateModule

4、加载翻译功能,创建一下就完事

TWSTranslateViewController *vc = [[TWSTranslateViewController alloc ] init];  

[self.navigationController pushViewController:vc animated:YES];

 

 

DHFBaseLib,拆分中遇坑及注意事项

1、需创建头文件,导入所有.m类


#import <DHFBaseLib/ThirdHeader.h>

#import <DHFBaseLib/ColorAndFontHeader.h>

#import <DHFBaseLib/FrameHeader.h>

#import <DHFBaseLib/EnumHeader.h>

#import <DHFBaseLib/DHFAlert.h>

#import <DHFBaseLib/TWSSevicesConst.h>

#import <DHFBaseLib/TWSDefaultConst.h>

#import <DHFBaseLib/TWSNotificationConst.h>

#import <DHFBaseLib/TWSBLEConst.h>

#import <DHFBaseLib/TWSGlobalSingle.h>

#import <DHFBaseLib/TWSDeviceDB.h>

2、使用第三库时,如果报错不能识别,需改成#import <SDWebImage/SDWebImage.h>,这样的方式使用

3、新项目安装、导入

pod'DHFBaseLib', :git => 'codeup.aliyun.com/64b9eb4c32e…', :tag => ‘1.0.1’

4、新项目安装运行报错,Sandbox: rsync.samba(50581) deny(1) file-write-create /Users/dhf/Library/Developer/Xcode/DerivedData/TestBaseLib-ghbbyqmmowaznwbsmjrrcomwnfye/Build/Products/Debug-iphoneos/TestBaseLib.app/Frameworks/AFNetworking.framework/.AFNetworking.DK5Sr8

5、项目中设置,build settings -> user scrip sandboxing -> NO

6、创建pch文件,导入#import <DHFBaseLib/DHFBaseLib.h>

DHF Common Module ,通用库遇坑记录****

 

1、DHFCommonModule里面的代码需要使用基础库DHFBaseLib中的类,可以在podspec中配置 s.prefix_header_contents  '#import <DHFBaseLib/DHFBaseLib.h>'

配置s.dependency 'DHFBaseLib',podfile中再安装DHFBaseLib

 

2、DHFCommonModule中依赖本地第三方框架s.vendored_frameworks = 'Pod/Classes/ATAuthSDK.framework','Pod/Classes//YTXMonitor.framework','Pod/Classes//YTXOperators.framework'

 

3、DHFCommonModule里面的代码需要使用基础库DHFBaseLib中的类,可以全局替换

 

项目中导入使用


pod 'DHFBaseLib', :git => 'https://codeup.aliyun.com/64b9eb4c32e3d43cbddbad4e/DHFBaseLib.git', :tag =>1.0.2-t02’

   

   pod 'DHFCommonModule', :git => 'https://codeup.aliyun.com/64b9eb4c32e3d43cbddbad4e/DHFCommonModule.git', :tag =>1.0.1-t03’


4、加载xib资源的方式

NSBundle *bundle = [NSBundle bundleForClass:[TWSNewPopViewController class]];

    TWSNewPopViewController *vc =[[TWSNewPopViewController alloc] initWithNibName:@"TWSNewPopViewController" bundle:bundle];

    [self.navigationController pushViewController:vc animated:YES];
    

5、重写xib初始化方法

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

    NSBundle *bundle = [NSBundle bundleForClass:[TWSNewPopContentVC class]];

    self = [super initWithNibName:NSStringFromClass([TWSNewPopContentVC class]) bundle:bundle];

    return self;

}

6、注册cell, 改变bundle加载路径

[self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([TWSNewPopCell class]) bundle:[NSBundle bundleForClass:[TWSNewPopCell class]]] forCellWithReuseIdentifier:@"TWSNewPopCell"];

    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([TWSPopEmptyCell class]) bundle:[NSBundle bundleForClass:[TWSPopEmptyCell class]]] forCellWithReuseIdentifier:@"TWSPopEmptyCell"];

7、gif图片不能加载,放资源包的根目录才可以

DHFBluetoothLib踩坑记录

DHFBluetoothLib踩坑记录

1、杰理SDK单独放一个库,DHFThirdLib

配置如下

  s.source_files = 'Pod/Classes/**/*'

  

  s.static_framework = true

  

  s.vendored_frameworks = 'Pod/Classes/*.{framework}'

  s.vendored_libraries  = 'Pod/Classes/*.{a}'

  

  s.prefix_header_contents = '#import <JL_BLEKit/JL_BLEKit.h>', '#import <JLDialUnit/JLDialUnit.h>'

2、杰理SDK运行报错

[!] The 'Pods-PROJECT_Example' target has transitive dependencies that include statically linked binaries: (DHFThirdLib)

需设置

s.static_framework = true 

podfile中不能加这个use_frameworks

 

3、报错如下,可能是库里面少了info.plist文件

Unable to install "testJLSDk"

Domain: com.apple.dt.MobileDeviceErrorDomain

Code: -402653103

4、关联第三方SDK

s.static_framework = true

s.vendored_frameworks = 'Pod/Classes/*.framework'

5、报错如下,可能是库里面少了info.plist文件

Unable to install "testJLSDk"

Domain: com.apple.dt.MobileDeviceErrorDomain

Code: -402653103

5、git add -f . 提交SDK 中的info.plist文件

 

6、运行项目中不能包含info.plist文件   7、配置如下

Pod::Spec.new do |s|

  s.name             = 'DHFBluetoothLib'

  s.version          = '1.0.0'

  s.summary          = 'A short description of DHFBluetoothLib'

  


  s.description      = <<-DESC

                        TODO: Add long description of the pod here.

                       DESC

  


  s.homepage         = 'https://codeup.aliyun.com/64b9eb4c32e3d43cbddbad4e/DHFBluetoothLib.git'

  s.license          = { :type => 'MIT', :file => 'LICENSE' }

  s.author           = { 'lxy' => '1538949997@qq.com' }

  s.source           = { :git => 'https://codeup.aliyun.com/64b9eb4c32e3d43cbddbad4e/DHFBluetoothLib.git', :tag => s.version.to_s }

  

  s.ios.deployment_target = '13.0'

  


  s.source_files = 'Pod/Classes/**/*'

  

  s.user_target_xcconfig = {'OTHER_LDFLAGS' => '-ObjC'}

  

  s.vendored_libraries  = 'Pod/Classes/*.{a}'

  s.vendored_frameworks = 'Pod/Classes/*.{framework}'

  

  s.static_framework = true

  s.prefix_header_contents = '#import <DHFBaseLib/DHFBaseLib.h>', '#import <JL_BLEKit/JL_BLEKit.h>', '#import <DHFBluetoothLib/DHFBluetoothLib.h>', '#import <JLDialUnit/JLDialUnit.h>'

  s.dependency 'DHFBaseLib'

  #s.dependency 'DHFThirdLib'

  


end

DHFHomeModule 踩坑记录

 

1、swift代码兼容问题,podspec中 配置路径

  s.swift_version = '5.0'

巨坑:framework不支持桥架文件配置

解决办法 : 新增 open 关键字

@objcMembers open class WidgetFunc:NSObject{}

@objc open func refreshAllWidget(){}

Xib资源的问题, 配置  s.resource_bundles 

  s.source_files = 'Pod/Classes/**/*'

  s.resource_bundles =  { 'DHFHomeModule' => 'Pod/Classes/**/*.{xib}' }

  s.user_target_xcconfig = {'OTHER_LDFLAGS' => '-ObjC'}

 
  s.vendored_libraries  = 'Pod/Classes/*.{a}'

  s.vendored_frameworks = 'Pod/Classes/*.{framework}' 

  s.swift_version = '5.0'

  s.static_framework = true

DHFAITranslateModule 踩坑

 

1、SDK运行报错

  s.libraries = 'c++', 'z' // 意思是导入系统库libc++和libz

  s.ios.framework = 'CFNetwork','CoreTelephony','SystemConfiguration'