美文网首页
Flutter 集成到现有iOS项目

Flutter 集成到现有iOS项目

作者: creazylee | 来源:发表于2020-09-16 09:58 被阅读0次

    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'
    

    相关文章

      网友评论

          本文标题:Flutter 集成到现有iOS项目

          本文链接:https://www.haomeiwen.com/subject/pvdcyktx.html