共计遇到三个问题,挨个剖析一下。
问题现象1:
- building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64
- building for iOS Simulator, but linking in object file built for iOS, file '/Users///framework/' for architecture arm64
问题分析:
字面意思来看,是说link了不支持模拟器的FrameWork,通常需要检查三方库,看看三方库是不是不支持模拟器,比如支付的早期就不支持模拟器。
Xcode12在编译模拟器的时候优先使用arm64架构编译,而过去打包模拟器是没有arm64的,arm64架构只适用于真机。因此报错linking了一个真机的FrameWork。
解决方案大致是(错误的方案):
I've seen quite a bit of weird behavior with frameworks, I think due to changes to the simulators to support Apple silicon. My temporary workaround is, in my app/extension targets, to add "arm64" to the Excluded Architectures build setting when building for the simulator (as your preview appears to be trying to do), and setting "Build Active Architecture Only" to No for all schemes. Might be worth a try.
Check if in your project for compiled target ->build settings -> user defined section (at the very bottom) you have defined VALID_ARCHS=arm64, if yes, delete it.
大致是说删除VALID_ARCHS=arm64,然后Build Active Architecture Only 设置为NO
实际测试,确实可行了。但是带来了新的问题,这样没法编译真机了……
解决方案(推荐2)
- build settings->excluded architectures 中加入arm64架构,代表不编译arm64架构。但是这种做法会导致无法编译真机,因为真机是arm64架构。所以需要勾选Any iOS Simulator SDK,解决。
- build settings->build active architecture only 设置为YES,代表仅编译当前项目中包含的架构。这个设置适用于模拟器和真机。
- 如果使用了XCConfig配置文件,那么设置EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64,效果同1
问题现象2:
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: ***.a have the same architectures (arm64) and can't be in the same fat output file
问题分析:
打包的时候设置Build Active Architecture Only为no则代表打适用于所有机型的包,Xcode11 打包的模拟器的.a默认支持i386、x86_64,Xcode12 打包的模拟器.a默认支持i386、x86_64、arm64。比Xcode11多了arm64,而arm64通常用于真机,因此在合并模拟器的.a和真机的.a的时候起了冲突。
解决方案:
打包的时候强制指定${CONFIG} ARCHS="i386 x86_64", Xcode 配置build settings->+user-defined->VALID_ARCHS = i386 x86_64,或者直接设置Architectures = i386 x86_64
问题现象3:
报错1:DemoApp.xcodeproj The linked framework **framework' is missing one or more architectures required by this target: armv7.
报错2:ld: in **, building for iOS, but linking in object file (**) built for iOS Simulator, file '*' for architecture arm64
问题分析:
既然Xcode12模拟器默认支持了arm64,那么我们直接打出一个模拟器的FrameWork,真机是否可以直接使用?
解决方案:
答案是不可以。真机无法使用模拟器的arm64。报错1是直接使用模拟器的包编译会提示找不到armv7,改了build active architecture only后报错2。
Xcode12 提到了Universal APP(通用APP),MacOS11 的Apple芯片支持手机应用在电脑上运行。推测可能是苹果为新电脑做的适配,假设新电脑支持arm64,那就应该支持编译arm64的模拟器和真机。开发者大会有提及,但是细节不明。
解决方案:暂时只能老老实实回退到不包含arm64的模拟器包。