1.官方教程:
https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps
2.首先进入已有的iOS项目根目录,创建flutter模块
// 进入根目录
cd 到根目录
// 创建flutter模块 (模块的名字可以自己取,但是要遵循flutter的命名规则,我这里取名为flutter_module)
flutter create -t module flutter_module
3.创建完毕后,在你的podfile中添加如下代码
# flutter相关的设置
flutter_application_path = 'flutter_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb’)
/*
解释:
flutter_application_path后面跟的路径请根据你自己的目录结构自行修改.
我的flutter模块文件夹和我的podfile文件在同一级目录下.
*/
4.在podfile对应位置中添加如下代码
target 'FlutterInIos' do
# 引入flutter
install_flutter_engine_pod
install_all_flutter_pods(flutter_application_path)
end
5.示例,我的podfile文件内容如下:
# 设置源镜像 (用的是清华源)
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
# 消除三方库的警告
inhibit_all_warnings!
# 设置最低适配iOS系统版本
platform :ios, '9.0'
# flutter相关的设置
flutter_application_path = 'flutter_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
# 引入三方
target 'FlutterInIos' do
use_frameworks!
# oc 手写布局三方库
pod 'Masonry', '~> 1.1.0'
# 引入flutter
install_flutter_engine_pod
install_all_flutter_pods(flutter_application_path)
end
6.创建配置文件 debug.xcconfig, release.xcconfig, flutter.xcconfig
flutter.xcconfig内容如下
#include "../flutter_module/.ios/Flutter/Generated.xcconfig"
ENABLE_BITCODE=NO
// 路径根据自己的项目结构自行修改
debug.xcconfig 内容如下:
#include “flutter.xcconfig"
release.xcconfig内容如下:
#include "Flutter.xcconfig"
FLUTTER_BUILD_MODE=release
7.然后在项目中配置一下xcconfig文件
image.png8.引入头文件,就可以使用了
#import <Flutter/Flutter.h>
网友评论