Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Latest commit

 

History

History
92 lines (63 loc) · 6.68 KB

depend_flutter_remotely_upgrades.md

File metadata and controls

92 lines (63 loc) · 6.68 KB

iOS项目远程依赖Flutter Module产物 + Git Submodule + Shell脚本 (升级版 )

回顾一下之前整理的方案,远程依赖Flutter Module组件库编译产物(简单版)中将Flutter.xcframework、其它.xcframework、podspec都放在一个Git仓库上,iOS端远程依赖这个Git,但是由于Flutter.xcframework文件太大,导致提交到仓库、从仓库拉取耗时过久。在iOS项目远程依赖FlutterModule组件库代码(5个可行方案)中,整理了5个可行的远程或中转依赖方案,我个人选择 远程依赖Flutter Module组件库编译产物 方案0x05来实现远程依赖,即经本地podspec中转远程zip & git混合依赖,podspec文件统一放到独立仓库flutter_module_sdk_podspec.git管理,并基于这个方案实现了远程依赖Flutter Module组件库构建脚本flutter_build_script.sh

但是这个方案在iOS这端,除了克隆本身iOS项目的Git外,还需要克隆flutter_module_sdk_podspec.git仓库,并且要求所有人的电脑上这2个本地git仓库的相对路径是一模一样的,不然容器出现Git冲突。这就需要所有人都遵守这个约定/规则,在本机上手动克隆2个仓库,只要大家保持本机上2个git仓库的相对路径一致,就没什么问题。但是到了CI构建的机器上,就需要用脚本来实现这个规则,流程会显得有点繁杂。所以面临一个问题,就是怎么把flutter_module_sdk_podspec.gitiOS.git形成强关系的绑定,而不是靠不稳定的人为约定去保持弱关系的关联。 碰巧看到了一个大佬整理的《Git中submodule的使用》,详细介绍了git submodule,刚好能解决前面的问题,将flutter_module_sdk_podspec.git "内嵌"到iOS.git里面,形成强关系的绑定。

所以我又基于 远程依赖Flutter Module组件库编译产物 方案0x05 增加了git submodule,从Flutter编译到产物分发的流程没有变动(即步骤1-8),只是改了iOS一侧的流程,详细的介绍如下。

插一句:我介绍的例子都有提到2个Git,即flutter_app_sdk.git和flutter_plugin_sdk.git,其实可以整合成一个Git存放xcframework。  
拆不拆都可以,流程和思路是一样的,我个人建议不拆。

Flutter编译 -> 产物分发

  • 1.建立Git仓库flutter_module_sdk_podspecflutter_app_sdk.gitflutter_plugin_sdk.git备用;
  • 2.编译出 Flutter.podspec 、App.framework、FlutterPluginRegistrant.xcframework和其它第三方库 比如 flutter_boost.xcframework;
  flutter build ios-framework --cocoapods --xcframework --no-universal --output=../flutter_build/Frameworks/
  • 3.将App.framework移到flutter_app_sdk.git本地仓库根目录;FlutterPluginRegistrant.xcframework和其它第三方库移到flutter_plugin_sdk.git本地仓库根目录;
  • 4.打相同的版本标签,分别提交到远程仓库,即flutter_app_sdk.gitflutter_plugin_sdk.git
  • 5.在flutter_module_sdk_podspec根目录创建FlutterAppSDK.podspecFlutterPluginSDK.podspec文件,s.source设置成:git => 'http://gitlab.private.cn/flutter/flutter_..._sdk.git', :tag => '..version'
  • 6.将Flutter.podspec移到flutter_module_sdk_podspec根目录,因为有现成的zip资源,就不需要我们上传了,podspec文件也不用改,直接用就行;
  • 7.清空删除flutter_build,临时中转站,完事就没用了;
  • 8.在flutter_module_sdk_podspec.git执行commit & push,不用打标签;

flutter_module_sdk_podspec.git仓库目录:

  • Flutter.podspec
  • FlutterAppSDK.podspec
  • FlutterPluginSDK.podspec

iOS侧导入依赖

这里我们使用git submoduleflutter_module_sdk_podspec.git "内嵌"到iOS.git中,这样就能保住每台电脑上这2个git的相对路径是始终一致的,不用担心人为因素导致路径不一致的问题。之后更新子模块 等同于 更新依赖的flutter_module_sdk_podspec.git,这里又分3种情况,1.首次添加子模块、2.新同事首次克隆ios.git、3.拉取更新子模块。

  • 9.1.首次导入submodule需要在iOS.git本地路径下添加git submodule
  cd $HOME/Desktop/workspace/ios.git
  git submodule add 'http://gitlab.private.cn/flutter_module_sdk_podspec.git'
  • 9.2.新同事首次克隆iOS.git,可能会遇到2种情况。

一:普通常规的克隆指令,可能指定分支,但没有拉取submodule子模块,就需要额外执行指令去递归拉取更新子模块。

  git clone -b a_branch http://gitlab.private.cn/ios/ios.git 
  git submodule update --init --recursive

二:克隆的同时指定递归拉取更新子模块,需要在指令中加上--recurse-submodules

  git clone -b a_branch http://gitlab.private.cn/ios/ios.git --recurse-submodules
  • 9.3.flutter_module_sdk_podspec.git发布更新后,需要在ios.git中更新本地子模块,加上foreach可以帮助我们遍历所有的子模块。
  git submodule foreach 'git pull origin master'
  • 9.4.前面3种情况,如果更新了子模块,在ios.git都会产生modify,所以都需要提交更新到ios.git
  git status
  # 下面2步可以在SourceTree之类的客户端操作可以看到 submodule的
  git add -A && git commit -m "add or modify submodule flutter_module_sdk_podspec.git"
  git push origin --tags && git push origin master 
  • 10.在Podfile中添加本地依赖,pod update or install,即可运行代码;
  pod 'Flutter', :podspec => './flutter_module_sdk_podspec/Flutter.podspec'
  pod 'FlutterAppSDK', :podspec => './flutter_module_sdk_podspec/FlutterAppSDK.podspec'
  pod 'FlutterPluginSDK', :podspec => './flutter_module_sdk_podspec/FlutterPluginSDK.podspec'

至此iOS远程Flutter组件库的尝试就结束了(2021.07.28),前前后后花了近2周时间,也找到了个人觉得OK的方案。加上构建脚本(传送门🚪远程依赖Flutter Module组件库构建脚本flutter_build_script.sh),结合起来用能节省很多时间。