背景:公司前端项目要集成Flutter技术,经过层层筛选,此处省略5000字,大家可以自行Google或者度娘 Flutter和ios混合方案官方方案,最终决定采用私有库的形式引入到项目中,这样做的有点,对原生项目侵入最小,原生项目不需要配置Flutter环境,对于Flutter打包成私有库的形式也更容易进行Flutter版本控制。废话不多,搞起!
- 第一步创建私有库 pod lib create FlutterSDK,会自动生成FlutterSDK文件夹,这里需要注意 ruby2.*版本的时候你你需要这样:
xingkunkun:FlutterForFW admin$ pod lib create FlutterSDK
Cloning `https://github.com/VixHi/vvtable.git` into `FlutterSDK`.
Configuring MyFlutterPod template.
------------------------------
To get you started we need to ask a few questions, this should only take a minute.
What platform do you want to use?? [ iOS / macOS ]
> iOS
What language do you want to use?? [ Swift / ObjC ]
> objc
Would you like to include a demo application with your library? [ Yes / No ]
> no
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> none
Would you like to do view based testing? [ Yes / No ]
> no
What is your class prefix?
> DZJ
Running pod install on your new library.
ruby3.*版本会直接生成对应的文件夹如下图,注意NAME.podspec文件,可以更改名称-->FlutterSDK.podspec
- 第二步配置.podspec
Pod::Spec.new do |s|
s.name = "FlutterSDK" #名称
s.version = "0.2.17" #版本
s.platform = :iOS
s.ios.deployment_target = "9.0"
s.summary = "Flutter SDK."
s.license = { :type => "MIT", :file => "LICENSE" }
s.homepage = "http://172.29.28.7/vix/test-responsible"
s.author = { "vixhi" => "hi_vix@163.com" }
s.source = { :git => "https://github.com/Vix_Hi/vvtable.git", :tag => s.version.to_s }
s.static_framework = true
s.vendored_frameworks = "flutter_lib/*.framework" #flutter_lib文件和.podspec在同一目录
s.pod_target_xcconfig = { "VALID_ARCHS" => "x86_64 armv7 arm64" } #设置支持的架构
end
- 第三步,将Flutter打包的库拷贝到flutter_lib目录下
- 第四步,制作命令行操作
1.添加本地pod库
pod repo add FlutterSDK 远程库地址例如:https://github.com/Vix_Hi/test.git
FlutterSDK这个就是你要创建的私有库的名称
2.将Flutter打包的库提交到远端
添加远端仓库 git remote add Flutter 远程库地址例如:https://github.com/Vix_Hi/test.git
git add flutter_lib
git commit -m "FlutterSDK 制作"
git push Flutter
3.打tag
git tag -a "0.1.0" -m "my flutterSDK tag"
git push Flutter 0.1.0
4.库验合法性
pod spec lint FlutterSDK.podspec --verbose
pod repo push FlutterSDK FlutterSDK.podspec
5.成功之后可以自己搜索一下看能不能搜索到
pod search FlutterSDK
如果搜索不到继续往下看:
pod repo update FlutterSDK
搜索看看能否搜索到,如果还不能继续往下看
pod repo remove FlutterSDK
pod repo add FlutterSDK 远程库地址例如:https://github.com/Vix_Hi/test.git
rm ~/Library/Caches/CocoaPods/search_index.json
如果配置都没有错误的话,然后再尝试搜索应该就可以了。
制作过程中遇到的错误可以参考这片文章podspec 校验报错问题指南