【Flutter】和原生混合开发,通过cocoapods打包给原生使用

上一篇文章是通过终端指令打包flutter为framework,这一篇我们使用cocoapods打包framework!
1.在终端进入Flutter项目里:cd xx/xx/xx/flutter_module

cd xx/xx/xx/flutter_module

2.在终端输入 flutter build ios-framwork --cocoapods --output=../flutter_app,构建混合工程,../flutter_app 为你想要的的混合过程路径。

flutter build ios-framwork --cocoapods --output=../flutter_app

3.构建完成后,flutter_app 下会同样也会有三个目录:Debug、Profile、release,没个目录下有两个framework:App.xcframework(提供Flutter项目开发的代码)、Flutter.podspec(Flutter 环境)。


图1.jpg

4.将App.xcframework、Flutter.podspec导入到原生工程文件目录里,在:Target ->General->Frameworks,libraries,and Embedded content 里添加App.xcframework

  1. pod init,在podflie 里输入 pod 'Flutter',:podspec => '../Flutter.podspec' (Flutter.podspec 路径):
platform :ios, '12.0'

target 'NativeDemo' do
  use_frameworks!
  pod 'Flutter',:podspec => '../Flutter.podspec'
  # Pods for NativeDemo

end

5.pod install
6.编译运行,就OK了,可以在原生项目里开发flutter了。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容