1、flutter_module目录下执行以下命令
//选择不签名
flutter build ios --release --no-codesign
//构建模拟器的
flutter build ios --simulator
该命令会在build目录下iOS文件夹中生成.framework文件。
我这边使用了一个脚本,可参考如下:
#!/bin/zsh
#把生产的framework迁移出来好方便拷贝,路径是放在项目的script目录下,所以稍有调整
#先到脚本所在目录,为了无论执行脚本的目录在哪里都一样定位
BASEDIR=$(dirname $0)
cd $BASEDIR
cd '..'
build_dir=build/ios/Release-iphoneos
#build_dir=build/ios/Debug-iphoneos
target_path=ios_framework
mkdir -p $target_path
echo "clean build and target path:${target_path}"
find $target_path -name '*.framework' | xargs rm -rf
#echo "=========build======="
flutter build ios --release --no-codesign
echo "=========copy build to target========"
find $build_dir -maxdepth 2 -name '*.framework' |xargs -I F cp -r -fi "F" $target_path
#echo "=========delete duplicate files========"
cd $target_path
rm -rf 'Pods_Runner.framework'
上述脚本会在项目目录下生成一个ios_framework文件夹,并将.framework拷贝到这里。
2、将生成的.framework文件copy到另一个文件夹下,并配置一个podspec文件
参考如下:
我这边是copy到一个TestFlutterFrameWork文件夹下,并将framework放在xc_output/Release文件夹下
Pod::Spec.new do |spec|
spec.name = "TestFlutterFrameWork"
spec.version = "1.0.10"
spec.summary = "A short description of TestFlutterFrameWork."
spec.description = <<-DESC
This is xcframeworks for Flutter for TestiOSFlutter
DESC
spec.homepage = "http://EXAMPLE/TestiOSFlutter"
spec.license = { :type => "MIT", :file => "FILE_LICENSE" }
spec.author = { "xxx" => "xxxxx@xx.cn" }
spec.source = { :git => "https://xxxxxxxxx.git", :branch => "xxxx_1.0" }
#, :tag => "#{spec.version}"
# spec.source_files = "Classes", "Classes/**/*.{h,m}"
# spec.exclude_files = "Classes/Exclude"
# spec.public_header_files = "Classes/**/*.h"
spec.vendored_frameworks = 'xc_output/Release/*.framework'
end
3、回到原生iOS项目下,配置podfile文件
参考如下:
# Uncomment the next line to define a global platform for your project
platform :ios, '13.0'
FLUTTER_DEV_MODE = "false"
print "FLUTTER_DEV_MODE=", FLUTTER_DEV_MODE, "\n"
if FLUTTER_DEV_MODE == "true"
print "当前为flutter开发模式\n"
flutter_application_path = '../flutter_test_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
else
print "当前为flutter内嵌模式\n"
end
target 'testApp' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
if FLUTTER_DEV_MODE == "true"
install_all_flutter_pods(flutter_application_path)
else
pod 'TestFlutterFrameWork', :path => '../TestFlutterFrameWork'
end
# Pods for testApp
post_install do |installer|
if FLUTTER_DEV_MODE == "true"
flutter_post_install(installer) if defined?(flutter_post_install)
end
end
end
定义一个变量FLUTTER_DEV_MODE控制是本地集成,还是framework集成。
再将TestFlutterFrameWork以本地文件夹的形式引入pod
pod 'TestFlutterFrameWork', :path => '../TestFlutterFrameWork'
4、执行pod install
完成
遇到一个问题,就是没有生成FlutterPluginRegistrant.framework,后来发现,在flutter项目中随便引入一个插件库就可以了