将Flutter module嵌入到现有iOS App

环境: macOS10.15.1 CocoaPods1.84 Xcode11.2.1 Flutter 1.9.1+hotfix.6

该演示需要flutter项目和iOS项目位于同一级目录,如下FlutterModuleIntoiOSflutter_module_smples位于同一级目录下

├── FlutterModuleIntoiOS
│   ├── FlutterModuleIntoiOS
│   ├── FlutterModuleIntoiOS.xcodeproj
│   ├── FlutterModuleIntoiOS.xcworkspace
└── flutter_module_smples
    ├── README.md
    ├── build
    ├── flutter_module_smples.iml
    ├── flutter_module_smples_android.iml
    ├── lib
    ├── pubspec.lock
    ├── pubspec.yaml
    └── test

通过CocoaPods嵌入Flutter SDK

  1. 在需要的引入的iOS代码创建一个Podfile文件(已创建直接看第二步)
pod init
  1. 在Podefile添加以下内容
platform :ios, '9.0'

flutter_application_path = '../flutter_module_smples'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

target 'FlutterModuleIntoiOS' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  install_all_flutter_pods(flutter_application_path)
end
  • flutter_module_smples这个是flutter项目的所在的文件名
  • FlutterModuleIntoiOS iOS项目的Traget name
  1. 安装flutter moudle
pod install
image.png

如果出现这样,引入flutter成功

可能遇到的问题

Command PhaseScriptExecution failed with a nonzero exit code

脚本报错.png

Embed with CocoaPods and the Flutter SDK

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

推荐阅读更多精彩内容