Flutter 集成到现有iOS项目

2020-09-16  本文已影响0人  creazylee

iOS 接入

方法一:CocoaPods 接入

  1. Podfile 添加
flutter_application_path = '../my_flutter' // flutter 项目路径
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
  1. 在Podfile Target中添加
target 'MyApp' do
  install_all_flutter_pods(flutter_application_path)
end
  1. 允许 pod install

方法二:直接引入framework包

  1. 编译flutter ,生成framework
flutter build ios-framework --output=some/path/MyApp/Flutter/
some/path/MyApp/
└── Flutter/
    ├── Debug/
    │   ├── Flutter.framework
    │   ├── App.framework
    │   ├── FlutterPluginRegistrant.framework (only if you have plugins with iOS platform code)
    │   └── example_plugin.framework (each plugin is a separate framework)
    ├── Profile/
    │   ├── Flutter.framework
    │   ├── App.framework
    │   ├── FlutterPluginRegistrant.framework
    │   └── example_plugin.framework
    └── Release/
        ├── Flutter.framework
        ├── App.framework
        ├── FlutterPluginRegistrant.framework
        └── example_plugin.framework
  1. 链接framework到Xcode
Xcode > Build Phases > Link Binary With Libraries.
In the target’s build settings, add $(PROJECT_DIR)/Flutter/Release/ to the Framework Search Paths (FRAMEWORK_SEARCH_PATHS).

方法三: cocoapod + Embed frameworks

  1. 编译cocoapod 包
flutter build ios-framework --cocoapods --output=some/path/MyApp/Flutter/
some/path/MyApp/
└── Flutter/
    ├── Debug/
    │   ├── Flutter.podspec
    │   ├── App.framework
    │   ├── FlutterPluginRegistrant.framework
    │   └── example_plugin.framework (each plugin with iOS platform code is a separate framework)
    ├── Profile/
    │   ├── Flutter.podspec
    │   ├── App.framework
    │   ├── FlutterPluginRegistrant.framework
    │   └── example_plugin.framework
    └── Release/
        ├── Flutter.podspec
        ├── App.framework
        ├── FlutterPluginRegistrant.framework
        └── example_plugin.framework
  1. 配置podfile
pod 'Flutter', :podspec => 'some/path/MyApp/Flutter/[build mode]/Flutter.podspec'
上一篇下一篇

猜你喜欢

热点阅读