1、背景:
iOS工程使用module的方式接入Flutter
3.0.3版本使用正常,但是升级到3.3.8之后,出现Flutter/Flutter.h找不到。
2、3.0.3与3.3.8的差别
有3处差异:
2.1、 Flutter.xcframework
3.0.3 存在.ios/Flutter/engine目录下
3.3.8 不见了(后面会讲去哪儿了)
2.2、Flutter.podspec
3.0.3 vendored_frameworks有指定路径
s.vendored_frameworks = 'Flutter.xcframework'
3.3.8 vendored_frameworks有指定了一个空路径
# Framework linking is handled by Flutter tooling, not CocoaPods.
# Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs.
这里的注释告诉我们,Framework link由Flutter tools做了,不再是CocoaPods做了。
2.3、podhelper.rb
经过我反复切换版本,发现只要我pod instal,上面说的2点差异就会出现,初步断定可能跟pod脚本有关。
3.0.3版本 会将fluttersdk下面的/bin/cache/artifacts/engine/ios-release的Flutter.xcframework拷贝到.ios/Flutter/engine目录下。
3.3.8版本删除了拷贝动作,直接用脚本链接到fluttersdk下面的/bin/cache/artifacts/engine/ios-release的 Flutter.xcframework。
查看/packages/flutter_tools/bin/podhelper.rb的flutter_additional_ios_build_settings方法得知,pod组件必须要有s.dependency 'Flutter'才会链接。
# Skip other updates if it's not a Flutter plugin (transitive dependency).
next unless target.dependencies.any? { |dependency| dependency.name == 'Flutter' }
链接的代码:
# Profile can't be derived from the CocoaPods build configuration. Use release framework (for linking only).
configuration_engine_dir = build_configuration.type == :debug ? debug_framework_dir : release_framework_dir
Dir.new(configuration_engine_dir).each_child do |xcframework_file|
next if xcframework_file.start_with?('.') # Hidden file, possibly on external disk.
if xcframework_file.end_with?('-simulator') # ios-arm64_x86_64-simulator
build_configuration.build_settings['FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]'] = "\"#{configuration_engine_dir}/#{xcframework_file}\" $(inherited)"
elsif xcframework_file.start_with?('ios-') # ios-arm64
build_configuration.build_settings['FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]'] = "\"#{configuration_engine_dir}/#{xcframework_file}\" $(inherited)"
# else Info.plist or another platform.
end
end
build_configuration.build_settings['OTHER_LDFLAGS'] = '$(inherited) -framework Flutter'
解决
在报错的组件xxx.podspec里面添加
s.dependency 'Flutter'