xcode Codesign 返回 1(对象文件格式无效或不合适)错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7425840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:56:18  来源:igfitidea点击:

Codesign returned 1 (object ifile format invalid or unsuitable) bug

iosxcodecodesign

提问by RonC

I'm working with Xcode 4.1 build 4B110f trying to get my iOS app ready for upload. It passes the Product|Archive step with no errors, asking twice for permission to sign something. But when I try a validate of the archive from the Organizer, it fails:

我正在使用 Xcode 4.1 build 4B110f 尝试让我的 iOS 应用程序准备好上传。它通过了 Product|Archive 步骤,没有错误,两次请求签署某些东西的许可。但是当我尝试从组织者那里验证档案时,它失败了:

### Codesigning '/Users/uqrchern/Library/MobileDevice/Provisioning Profiles/70D2381D-3733-4F5D-88B2-4729572C2864.mobileprovision' with 'iPhone Distribution: Ron Chernich'
+ /usr/bin/codesign --force --preserve-metadata --sign iPhone Distribution: Ron Chernich --resource-rules=/var/folders/ul/ula1AHKnGpqQ9ftDnUL-l++++TM/-Tmp-/rybczU3EBd/Payload/ABRA-D.app/ResourceRules.plist --entitlements /var/folders/ul/ula1AHKnGpqQ9ftDnUL-l++++TM/-Tmp-/rybczU3EBd/entitlements_plistrZ1Vwko6 /var/folders/ul/ula1AHKnGpqQ9ftDnUL-l++++TM/-Tmp-/rybczU3EBd/Payload/ABRA-D.app
Program /usr/bin/codesign returned 1 : [/var/folders/ul/ula1AHKnGpqQ9ftDnUL-l++++TM/-Tmp-/rybczU3EBd/Payload/ABRA-D.app: replacing existing signature
/var/folders/ul/ula1AHKnGpqQ9ftDnUL-l++++TM/-Tmp-/rybczU3EBd/Payload/ABRA-D.app: object file format invalid or unsuitable
]
error: codesign failed with error 1

I've looked at all the similar problems and solutions (some of which make no sense whatever, or apply to really old versions of the tools). None have made the slightest difference.

我已经查看了所有类似的问题和解决方案(其中一些没有任何意义,或者适用于非常旧版本的工具)。没有一个有丝毫的不同。

I've also checked 3 times that verify is using the "production" certificate, as is the codesign step that produces the archive. I've even turned the above output into a schell script so I could try all certificates manually: same result every time.

我还检查了 3 次验证是否使用“生产”证书,以及生成存档的协同设计步骤。我什至将上面的输出变成了一个 schell 脚本,这样我就可以手动尝试所有证书:每次都得到相同的结果。

Maybe the .app file being signed really is unsuitable?

也许正在签名的 .app 文件真的不合适?

Incidentally, codesign has no version flag, but the man page is dated June 1 2006. The binary has a file date of Nov 20 2010.

顺便提一下,codesign 没有版本标志,但手册页的日期是 2006 年 6 月 1 日。二进制文件的文件日期是 2010 年 11 月 20 日。

UPDATE (next day):

更新(第二天):

Researching the problem further found an obscure reference saying that codesign needs the following environment var set:

进一步研究这个问题,发现一个晦涩的参考文献说 codesign 需要以下环境变量集:

CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate

Using the output from a failed Validate run, I created a shell script which exported this var just before the failing codesign --force step and viola! The codesign works.

使用失败的 Validate 运行的输出,我创建了一个 shell 脚本,它在失败的 codesign --force step 和 viola 之前导出了这个 var!协同设计有效。

But this does not really help me prepare my code for upload. Is there a way to include this into the script run by the Organizer Validate button??

但这并不能真正帮助我准备上传代码。有没有办法将其包含在由 Organizer Validate 按钮运行的脚本中?

A LITTLE LATER STILL, THE SOLUTION! :

稍后,解决方案!:

Under the theory there is a script someplace which generates all the commands run during an Organizer Validate... run, I did some digging with grep and find. The script indeed exists and it's name is:

根据该理论,某个地方有一个脚本可以生成在 Organizer Validate... 运行期间运行的所有命令,我用 grep 进行了一些挖掘并找到。该脚本确实存在,它的名称是:

/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication

It's just Perl and the fix is to add the required environment var to the associative array %ENV right at the start, say at line 72:

这只是 Perl,解决方法是在开始时将所需的环境变量添加到关联数组 %ENV 中,例如第 72 行:

$ENV{CODESIGN_ALLOCATE} = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate';

This totally fixes the problem.I've no idea where all the other posters on the web who think they fixed it by combinations of deleting certificates, building clean, shutting down and restarting Xcode, etc, etc are coming from. I'll just quietly assert that this fix favors science over superstition and works for me under Xcode 4.1 Build 4B110f and its associated PackageApplication script, running under Snow Leopard 10.6.8 with Perl 5.10.0

这完全解决了问题。我不知道网络上所有其他认为他们通过删除证书、构建清理、关闭和重新启动 Xcode 等组合来修复它的海报来自哪里。我只是悄悄地断言,这个修复程序有利于科学而不是迷信,并且在 Xcode 4.1 Build 4B110f 及其相关的 PackageApplication 脚本下对我有用,在雪豹 10.6.8 和 Perl 5.10.0 下运行

回答by Jon Egeland

Just so that this can be taken off the unanswered list. Like you said, you need to add CODESIGN_ALLOCATEto the $ENVarray:

只是为了将其从未答复的列表中删除。就像你说的,你需要添加CODESIGN_ALLOCATE$ENV数组中:

$ENV{CODESIGN_ALLOCATE} = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate';

If everyone is in agreement here, I think this question can finally be closed.

如果大家都同意,我想这个问题终于可以结束了。

When using a more recent version of Xcode, the default location is:

使用更新版本的 Xcode 时,默认位置为:

$ENV{CODESIGN_ALLOCATE} = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate';

回答by richardwhiuk

In case you get this on a recent version of Xcode, what you actually want is, in the shell:

如果你在最新版本的 Xcode 上得到这个,你真正想要的是,在 shell 中:

export CODESIGN_ALLOCATE=`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate

which will use the codesign_allocate from the version of Xcode you are using.

它将使用您正在使用的 Xcode 版本中的 codesign_allocate。

You can update the version of Xcode the command line tools use by running xcode-select -switch

您可以通过运行 xcode-select -switch 来更新命令行工具使用的 Xcode 版本

回答by Dan J

I had this workaround in place for a long time, but after upgrading to Xcode 4.3 with iOS 5.1 SDK, my signing script (which calls codesign) stopped working with a cannot find code object on diskerror:

我有很长一段时间都采用这种解决方法,但是在使用 iOS 5.1 SDK 升级到 Xcode 4.3 后,我的签名脚本(调用codesign)停止工作,出现cannot find code object on disk错误:

output/Enterprise/Payload/MyProduct.app/MyProduct: replacing invalid existing signature    
output/Enterprise/Payload/MyProduct.app/MyProduct: cannot find code object on disk     
Code signing failed, not creating .ipa file    

It seems this workaround isn't necessary for binaries built with Xcode 4.3. To fix, I updated my bash script to check if the location exists before exporting it:

对于使用 Xcode 4.3 构建的二进制文件,似乎不需要这种解决方法。为了解决这个问题,我更新了我的 bash 脚本以在导出它之前检查该位置是否存在:

  # Only export the environment variable if the location exists,
  # otherwise it breaks the signing process!
  if [ -f "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate" ]
  then
    echo Export environment variable for codesign_allocate location
    export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
  fi