【Flutter/IOS混编】flutter build ios-framework打出xcframework问题

邹高懿
2023-12-01

昨天下午更新了最新版的Flutter,版本如下:

Flutter 1.24.0-10.2.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 022b333a08 (4 周前) • 2020-11-18 11:35:09 -0800
Engine • revision 07c1eed46b
Tools • Dart 2.12.0 (build 2.12.0-29.10.beta)

按照往常在编写完Flutter代码之后执行了

flutter build ios-framework --output=./ios_flutter/

结果在Xcode原生应用中build时直接报错,找不到flutter.h

打开./ios_flutter目录一看,发现原来build出来的所有.framework框架都变成了.xcframework框架

(二者具体区别不做介绍分析,⚠️注意Xcode11之后才支持.xcframework)

导致原生项目引入的路径找不到对应框架。

由于指令--help和官方文档都没有关于flutter build ios-framework指令参数的说明,所以到flutter源码中去看一下。

链接:https://github.com/flutter/flutter/tree/master/packages/flutter_tools/lib (这个链接包括了所有flutter command指令)

这里只摘取flutter build ios-framework部分

    argParser
      ..addFlag('debug',
        negatable: true,
        defaultsTo: true,
        help: 'Whether to produce a framework for the debug build configuration. '
              'By default, all build configurations are built.'
      )
      ..addFlag('profile',
        negatable: true,
        defaultsTo: true,
        help: 'Whether to produce a framework for the profile build configuration. '
              'By default, all build configurations are built.'
      )
      ..addFlag('release',
        negatable: true,
        defaultsTo: true,
        help: 'Whether to produce a framework for the release build configuration. '
              'By default, all build configurations are built.'
      )
      ..addFlag('universal',
        help: '(Deprecated) Produce universal frameworks that include all valid architectures. '
              'This option will be removed in a future version of Flutter.',
        negatable: true,
        hide: true,
      )
      ..addFlag('xcframework',
        help: 'Produce xcframeworks that include all valid architectures.',
        defaultsTo: true,
      )
      ..addFlag('cocoapods',
        help: 'Produce a Flutter.podspec instead of an engine Flutter.xcframework (recommended if host app uses CocoaPods).',
      )
      ..addOption('output',
        abbr: 'o',
        valueHelp: 'path/to/directory/',
        help: 'Location to write the frameworks.',
      )
      ..addFlag('force',
        abbr: 'f',
        help: 'Force Flutter.podspec creation on the master channel. For testing only.',
        hide: true
      );

可以看到xcframework被设置为了默认参数,与之对应的universal则已经被标为Deprecated

重新执行指令

flutter build ios-framework --universal --output=./ios_flutter/

会有提示,但是目前还能正常build

--universal has been deprecated to support Apple Silicon ARM simulators and will be removed in a future version of Flutter. Use --xcframework instead.

执行完毕后./ios_flutter目录下有了一份framework和一份xcframework,原生应用可以正常引用.framework


由于universal参数已经被标记为废弃,所以尝试更改原生的引用路径,把App.framework改为App.xcframework进行测试,其他引用保持.framework不变

经过Archive打包签名没有问题。主要是因为xcframework其实本质上就是让Xcode进行一次framework分发(个人理解),所以不会影响实际的打包签名。

 

 

 

 

 

 

 类似资料: