归档iOS项目时遇codesign错误:退出代码1及未知错误-1
我之前也踩过这个一模一样的codesign错误坑,折腾了好几个小时才搞定,先把你的问题场景理清楚,再给你几个亲测有效的解决步骤:
你的问题场景
归档iOS项目时触发CodeSign操作失败,执行的签名命令是:
CodeSign /Users/admin/Library/Developer/Xcode/DerivedData/POC2-byrqqhzjppbjxjemdbcmskhttxdm/Build/Products/Debug-iphoneos/POC2.app/Frameworks/MicroBlink.framework cd /Users/admin/Documents/Development/POC2 export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" Signing Identity: "iPhone Distribution: **************name ***** (********)" /usr/bin/codesign --force --sign 4070CCDBD98188BA13DE80C8A094CCDFAC2A2E4C --preserve-metadata=identifier,entitlements,flags --timestamp=none /Users/admin/Library/Developer/Xcode/DerivedData/POC2-byrqqhzjppbjxjemdbcmskhttxdm/Build/Products/Debug-iphoneos/POC2.app/Frameworks/MicroBlink.framework
执行后弹出的错误提示:
/Users/admin/Library/Developer/Xcode/DerivedData/POC2-byrqqhzjppbjxjemdbcmskhttxdm/Build/Products/Debug-iphoneos/POC2.app/Frameworks/MicroBlink.framework: replacing existing signature
/Users/admin/Library/Developer/Xcode/DerivedData/POC2-byrqqhzjppbjxjemdbcmskhttxdm/Build/Products/Debug-iphoneos/POC2.app/Frameworks/MicroBlink.framework: unknown error -1=ffffffffffffffff
最终报错:Command /usr/bin/codesign failed with exit code 1
亲测有效的排查&解决步骤
先清理DerivedData再重来
Xcode的DerivedData缓存真的是各种奇怪问题的重灾区,直接删掉/Users/admin/Library/Developer/Xcode/DerivedData/POC2-byrqqhzjppbjxjemdbcmskhttxdm这个文件夹,重启Xcode,按Cmd+Shift+K清一下项目,再重新build或者归档试试,大概率能解决。检查证书和描述文件是否正常
确认你的iPhone Distribution证书没过期,对应的Provisioning Profile包含了当前项目的Bundle ID,而且已经正确导入Xcode了。可以去Xcode的Preferences > Accounts里刷新一下证书,重新下载对应的描述文件,避免出现证书不匹配的情况。移除第三方框架的原有签名再重签
像MicroBlink这种第三方框架,有时候本身已经被签名过了,重复签名就会冲突。你可以先手动移除它的原有签名:codesign --remove-signature /Users/admin/Library/Developer/Xcode/DerivedData/POC2-byrqqhzjppbjxjemdbcmskhttxdm/Build/Products/Debug-iphoneos/POC2.app/Frameworks/MicroBlink.framework删完之后再让Xcode自动重新签名,或者手动执行签名命令试试。
检查Xcode和系统版本是否兼容
旧版本Xcode和新版本macOS经常会出现签名工具不兼容的问题,比如你用的是Ventura系统,尽量升级到Xcode 14以上的稳定版,版本匹配了很多奇怪问题都会消失。检查钥匙串里的证书权限
打开钥匙串访问,找到你的Distribution证书,右键选Get Info,在Access Control标签里,看看codesign有没有被允许访问这个证书。如果没有的话,点击+添加/usr/bin/codesign,暂时选Allow all applications to access this item(解决后可以改回来,避免安全风险),然后再试签名。加-v参数看详细日志
手动执行签名命令的时候加上-v,能拿到更详细的错误信息,方便定位到底是权限、证书还是框架本身的问题:/usr/bin/codesign -v --force --sign 4070CCDBD98188BA13DE80C8A094CCDFAC2A2E4C --preserve-metadata=identifier,entitlements,flags --timestamp=none /Users/admin/Library/Developer/Xcode/DerivedData/POC2-byrqqhzjppbjxjemdbcmskhttxdm/Build/Products/Debug-iphoneos/POC2.app/Frameworks/MicroBlink.framework
内容的提问来源于stack exchange,提问作者thobio joseph

