fatal error: have the same architectures (arm64) and can't be in the same

686 阅读1分钟

have the same architectures (arm64) and can't be in the same fat output file

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: /Users/lz/Library/Caches/org.carthage.CarthageKit/DerivedData/(...)/Zip.framework/Zip have the same architectures (arm64) and can't be in the same fat output file

fatal error ApplicationsXcode.appContentsDeveloperToolchainsXeodeDefault.png

分析

  • Xcode12之前:

    • 编译模拟器静态库支持i386x86_64两架构;
    • 编译真机静态库支持armv7arm64两架构。

    在使用lipo -create -output命令可以将两个库合并成一个支持模拟器和真机i386x86_64armv7arm64四种架构的融合库。

  • Xcode12之后:

    • 编译的模拟器静态库也支持了arm64

    导致出现真机库和模拟器库不能合并的问题。(因为arm64被重复融合)

  • 融合真机与模拟器库的方法

    lipo -create 真机文件路径 模拟器文件路径 -output 真机文件路径
    
    • 查看framework包含内容方法:
       lipo -info framework的路径
      
    • M1的Mac之后编译的模拟器framework只有arm64了,x86_64的没有了。这时需要用到另一个设置,Target->BuildSetting-->VALID_ARCHS,在这里是描述你编译时需要包含哪些架构的,在后面添加上x86_64image.png

解决办法:

1.如果有静态库工程:在工程里面进行如下设置(译出来的包中就不会包含arm64)

Build Settings -> Excluded Architectures里按照这样设置一下,再编译合并就不会报错了。

2.如果手里只有.a或.framework文件,使用lipo remove命令将模拟器库的arm64架构移除

lipo XXX.a -remove arm64 -output XXX.a