iOS原生项目引入Flutter模块(配置)

154 阅读1分钟

Android Studio创建Flutter模块

首先通过Android Studio 创建一个flutter module项目,注意用小写和下划线命名

module.png

将已有的原生项目拷贝到和flutter项目放到一个目录下

截屏2022-02-16 下午2.48.21.png

cocopods 引入Flutter模块

编辑podflile 如下:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

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

target 'NativeDemo' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for NativeDemo
#指定需要安装的flutter模块
  install_all_flutter_pods(flutter_application_path)

end

pod install

截屏2022-02-16 下午2.58.14.png

添加脚本

添加Flutter目录宏

截屏2022-02-16 下午3.04.11.png

添加shell脚本

"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build

"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed

截屏2022-02-16 下午3.08.25.png

原生模块引入flutter

导入#import <Flutter/Flutter.h>头文件

self.window.rootViewController = [[FlutterViewController alloc] init];
[self.window makeKeyAndVisible];

运行项目

截屏2022-02-16 下午3.18.28.png