集成
集成使用的是闲鱼出品的Flutter Boost,集成方式很简单,没有遇到什么坑,具体参考flutter_boost的github,有详细的集成使用说明和例子,这里不在叙述:
相对于使用Flutter官方推荐集成方式而言,使用flutterBoost集成方式有以下优点,直接拷贝闲鱼官方说法如下:
官方的集成方案有诸多弊病:
- 日志不能输出到原生端;
- 存在内存泄漏的问题,使用boost可以让内存稳定;
- native调用flutter,flutter调用native,通道的封装,使开发更加简便;
- 同时对于页面生命周期的管理,也梳理的比较整齐
打包
把flutter项目成功集成到iOS项目后,Debug运行各项功能,跳转均正常,然后开始Adhoc打包,坑又开始出现了:
使用命令flutter build ios 编译flutter_module,然后在iOS项目打包,报错如下:
/Users/ios/Library/Developer/Xcode/DerivedData/Runner-arwzutrlpazzxehkoznuqlffxqkq/Build/Intermediates.noindex/ArchiveIntermediates/Runner/InstallationBuildProductsLocation/Applications/Runner.app/Frameworks/App.framework/App: signed bundle with Mach-O universal (x86_64 arm64) [io.flutter.flutter.app]
/Users/ios/Library/Developer/Xcode/DerivedData/Runner-arwzutrlpazzxehkoznuqlffxqkq/Build/Intermediates.noindex/ArchiveIntermediates/Runner/InstallationBuildProductsLocation/Applications/Runner.app/Frameworks/Flutter.framework/Flutter: replacing existing signature
/Users/ios/Library/Developer/Xcode/DerivedData/Runner-arwzutrlpazzxehkoznuqlffxqkq/Build/Intermediates.noindex/ArchiveIntermediates/Runner/InstallationBuildProductsLocation/Applications/Runner.app/Frameworks/Flutter.framework/Flutter: signed bundle with Mach-O universal (armv7 x86_64 arm64) [io.flutter.flutter]
fatal error: lipo: -extract armv7 specified but fat file: /Users/ios/Library/Developer/Xcode/DerivedData/Runner-arwzutrlpazzxehkoznuqlffxqkq/Build/Intermediates.noindex/ArchiveIntermediates/Runner/InstallationBuildProductsLocation/Applications/Runner.app/Frameworks/App.framework/App does not contain that architecture
Failed to extract armv7 for /Users/ios/Library/Developer/Xcode/DerivedData/Runner-arwzutrlpazzxehkoznuqlffxqkq/Build/Intermediates.noindex/ArchiveIntermediates/Runner/InstallationBuildProductsLocation/Applications/Runner.app/Frameworks/App.framework/App. Running lipo -info:
Architectures in the fat file: /Users/ios/Library/Developer/Xcode/DerivedData/Runner-arwzutrlpazzxehkoznuqlffxqkq/Build/Intermediates.noindex/ArchiveIntermediates/Runner/InstallationBuildProductsLocation/Applications/Runner.app/Frameworks/App.framework/App are: x86_64 arm64
Command PhaseScriptExecution failed with a nonzero exit code
分析错误输出(App.framework/App does not contain that architecture
Failed to extract armv7)这句,说明跟编译架构有关系,flutter项目编译生成的App.framework不包含armv7处理器架构,只有x86_64 arm64两种架构,所以打包的时候去掉armv7就可以了,做法是将Build Active Architecture Only中的Release改为Yes,然后在设备那里选择具体的设备即可~
参考自:
github.com/flutter/flu…
打包成功了~
因为现在iOS 64位架构已经普及了(iPhone5s之前的设备都是32位,已经很少有人还在用),所以可以在打包是强制只打包64位,也就是不去构建armv7和armv7s,具体操作是在Xcode->Target->Build Setting中将Build Active Architecture Only设置为YES,只针对当前活动设备架构,我当前连接的设备是iPhone7,架构是arm64,并将Vaild Architecture设置为 arm64,arm64e; (注:在Xcode12版本,Vaild Architecture这个选项没有了)
然后顺便复习了一下Xcode中Architectures指令集相关的知识:
Build Active Architecture Only
指定是否只对当前连接设备所支持的指令集编译 当其值设置为YES,这个属性设置为yes,是为了debug的时候编译速度更快,它只编译当前的architecture版本,而设置为no时,会编译所有的版本。 编译出的版本是向下兼容的,连接的设备的指令集匹配是由高到低(arm64 > armv7s > armv7)依次匹配的。比如你设置此值为yes,用iphone4编译出来的是armv7版本的,iphone5也可以运行,但是armv6的设备就不能运行。 所以,一般debug的时候可以选择设置为yes,release的时候要改为no,以适应不同设备。
如果对ipa安装包大小有要求,可以减少安装包的指令集的数量,这样就可以尽可能的减少包的大小。当然这样做会使部分设备出现性能损失,当然在普通应用中这点体现几乎感觉不到,至少不会威胁到用户体检。
指令集对应的机型:
2018 A12芯片arm64e : iphone XS、 iphone XS Max、 iphoneXR
2017 A11芯片arm64: iPhone 8, iPhone 8 Plus, and iPhone X
2016 A10芯片arm64:iPhone 7 , 7 Plus, iPad (2018)
2015 A9芯片arm64: iPhone 6S , 6S Plus
2014 A8芯片arm64: iPhone 6 , iPhone 6 Plus
2013 A7芯片arm64: iPhone 5S
armv7s:iPhone5|iPhone5C|iPad4(iPad with Retina Display)
armv7:iPhone4|iPhone4S|iPad|iPad2|iPad3(The New iPad)|iPad mini|iPod Touch 3G|iPod Touch4
模拟器32位处理器测试需要i386架构,
模拟器64位处理器测试需要x86_64架构,
真机32位处理器需要armv7,或者armv7s架构,
真机64位处理器需要arm64架构。