Featured image of post iOS已有项目导入Flutter

iOS已有项目导入Flutter

创建 Flutter module

  • cdiOS 项目的上一级目录
  • 执行 flutter create --template module ju_flutter

配置 iOS 项目的 Podfile

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// ①
#此处根据自己Flutter项目实际路径填写
flutter_application_path = '../ju_flutter'
#此句不可缺少
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

// ②
flutter_post_install(installer) if defined?(flutter_post_install)

// ③
install_all_flutter_pods(flutter_application_path)

NOTE: 注意① ② ③的位置

安装 Flutter

切到 iOS 项目目录,执行 pod install:

遇到问题:无法 import Flutter

Flutter中文网 将 Flutter module 集成到 iOS 项目 再对照教程及搜索:

  • Flutter framework 没有
    • 切到 ju_flutter
    • 执行 flutter pub get:
    • 执行 flutter build ios --no-codesign
  • 没有 Build the project
    • 创建桥接文件

      这里的截图用的是新建的一个项目,目的是验证是否这样配置,结果如自己所愿!

      在如下图的 iOSFlutterOne-Brdging-Header.h 中:

      1
      
      #import <Flutter/Flutter.h>
      

      最后,打开 iOS 项目,Select Product > Build or press Cmd + B.

成功导入

Licensed under CC BY-NC-SA 4.0
Built with Hugo
主题 StackJimmy 设计