共計(jì)遇到三個(gè)問題行楞,挨個(gè)剖析一下拗秘。
問題現(xiàn)象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在編譯模擬器的時(shí)候優(yōu)先使用arm64架構(gòu)編譯,而過去打包模擬器是沒有arm64的靴姿,arm64架構(gòu)只適用于真機(jī)沃但。因此報(bào)錯(cuò)linking了一個(gè)真機(jī)的FrameWork佛吓。
解決方案大致是(錯(cuò)誤的方案):
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 設(shè)置為NO
實(shí)際測試,確實(shí)可行了维雇。但是帶來了新的問題,這樣沒法編譯真機(jī)了……
解決方案(推薦2)
- build settings->excluded architectures 中加入arm64架構(gòu)吱型,代表不編譯arm64架構(gòu)逸贾。但是這種做法會導(dǎo)致無法編譯真機(jī),因?yàn)檎鏅C(jī)是arm64架構(gòu)津滞。所以需要勾選Any iOS Simulator SDK铝侵,解決。
- build settings->build active architecture only 設(shè)置為YES触徐,代表僅編譯當(dāng)前項(xiàng)目中包含的架構(gòu)咪鲜。這個(gè)設(shè)置適用于模擬器和真機(jī)。
- 如果使用了XCConfig配置文件撞鹉,那么設(shè)置EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64嗜诀,效果同1
問題現(xiàn)象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
問題分析:
打包的時(shí)候設(shè)置Build Active Architecture Only為no則代表打適用于所有機(jī)型的包,Xcode11 打包的模擬器的.a默認(rèn)支持i386孔祸、x86_64,Xcode12 打包的模擬器.a默認(rèn)支持i386发皿、x86_64崔慧、arm64。比Xcode11多了arm64穴墅,而arm64通常用于真機(jī)惶室,因此在合并模擬器的.a和真機(jī)的.a的時(shí)候起了沖突。
解決方案:
打包的時(shí)候強(qiáng)制指定${CONFIG} ARCHS="i386 x86_64", Xcode 配置build settings->+user-defined->VALID_ARCHS = i386 x86_64玄货,或者直接設(shè)置Architectures = i386 x86_64
問題現(xiàn)象3:
報(bào)錯(cuò)1:DemoApp.xcodeproj The linked framework **framework' is missing one or more architectures required by this target: armv7.
報(bào)錯(cuò)2:ld: in **, building for iOS, but linking in object file (**) built for iOS Simulator, file '*' for architecture arm64
問題分析:
既然Xcode12模擬器默認(rèn)支持了arm64皇钞,那么我們直接打出一個(gè)模擬器的FrameWork,真機(jī)是否可以直接使用松捉?
解決方案:
答案是不可以夹界。真機(jī)無法使用模擬器的arm64。報(bào)錯(cuò)1是直接使用模擬器的包編譯會提示找不到armv7隘世,改了build active architecture only后報(bào)錯(cuò)2可柿。
Xcode12 提到了Universal APP(通用APP)鸠踪,MacOS11 的Apple芯片支持手機(jī)應(yīng)用在電腦上運(yùn)行。推測可能是蘋果為新電腦做的適配复斥,假設(shè)新電腦支持arm64营密,那就應(yīng)該支持編譯arm64的模擬器和真機(jī)。開發(fā)者大會有提及目锭,但是細(xì)節(jié)不明评汰。
解決方案:暫時(shí)只能老老實(shí)實(shí)回退到不包含arm64的模擬器包。