上一篇文章是通过终端指令打包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 环境)。
4.将App.xcframework、Flutter.podspec导入到原生工程文件目录里,在:Target ->General->Frameworks,libraries,and Embedded content 里添加App.xcframework
- 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了。