xcodebuild archive fails, xcode archive succeeds xcodebuild archive fails, xcode archive succeeds shell shell

xcodebuild archive fails, xcode archive succeeds


Please check if you do not have any errors during archive process. Also please compare the logs between Xcode and command line output, it may help you understanding on which step compilation fails.

I had the same issue. Archive was failing without any specific reason, while .xcarchive was produced. I looked at build logs from xcode noticed that it finished with Build finished with errors message. Despite this error organizer was showing archive and I was able to export IPA from it.

When I reviewed that, I found out there was an archive error caused by broken PNG file, which couldn't be compressed during archive process. Error was non fatal, hence archive was being produced anyway. When I fixed PNG file everything started compiling smoothly without any issues.


This just happened to me, and it was for a different issues than with PNGs (maybe what follows is just the more general case though): I had a custom build phase which was outputting errors to stderr, but the build phase wasn't returning an exit code different from 0 in this case (using xcodebuild from Xcode 9.3 (9E145)).
The build phase was similar to:

find "${SRCROOT}/Directory" -print0 | <...>

Where ${SRCROOT}/Directory was renamed, and so find would output an error without failing the script: the build log would contain Command /bin/sh emitted errors but did not return a nonzero exit code to indicate failure right after executing the build phase.

While Xcode itself has no issues with it, xcodebuild would simply fail with **ARCHIVE FAILED** at the end, right after touching the DSYM.

The fix was to make sure that if a build phase outputs to stderr, the build phase correctly explicitely returns an exit code different from 0 (like 1). In my case, changing the path referenced in find fixed the issue.