Mark Struzinski
Mark Struzinski

Reputation: 33471

Archive in Xcode 4.5 - No errors, but build cancelled

I've been building iOS apps for > 2 years and never encountered this problem. I am attempting to archive an app for beta distribution. The build succeeds, but at the very end of the process, Xcode reports 'Archive Cancelled'.

enter image description here

The build logs show no warnings or errors of any kind.

enter image description here

Sometimes, by cleaning/cleaning build folder/wiping derived data, I can get the archive to succeed, but there seems to be no pattern to it. Has anyone encountered this issue? I don't even have anything to go on as far as an error message in this case.

Upvotes: 12

Views: 5769

Answers (8)

Tigran Khachatryan
Tigran Khachatryan

Reputation: 1

Just solved this issue by putting the script code into post actions in Build scheme.

Product -> Schemes -> Edit Scheme -> Build

Expand the build scheme and find Post actions there. Click "+" and add new run script.

Thats it.

Upvotes: 0

Trev14
Trev14

Reputation: 4116

Xcode 13.2.1 - Super Simple

You may have a version bump script throwing off the build process (as mentioned above). If that's the case, remove it and put this code below in a post build action (inside the Edit Scheme dialogue). It will bump all version numbers inside your project without causing the issue.

cd "${PROJECT_DIR}" ; agvtool bump

Here's my short blog post on the subject

After a ton of testing I realized a couple of things:

  • A lot of answers leave off the quotes around ${PROJECT_DIR} which prevents the change of directory to the project folder.
  • We can access agvtool directly, instead of using xcrun (at least when I have Xcode command line tools installed, I haven't tried this without them)
  • The new build system prevents archives from completing successfully when a build phase script uses agvtool to modify the project file.

Upvotes: 3

Binarian
Binarian

Reputation: 12446

I had the same problem. But I fixed it while still using avgtool.

I was using a Build Phases Run Script not as the last step and used the following script which caused errors:

"${DEVELOPER_BIN_DIR}/agvtool" next-version -all

My solution was to use Build Phases Run Script as last phase and change the script to the folling

agvtool bump

Upvotes: 0

Arka Mukherjee
Arka Mukherjee

Reputation: 2300

In my case, I started getting this issue a lot after updating my XCode version. This is what I did to fix it:

  1. Click on the "hammer" icon on the top bar in XCode. enter image description here

  2. Select "Legacy Build System" in the Build System tab.

  3. Click on done.

The application should build without this issue after this if you are working on an older project and everything seems to get compiled.

Upvotes: -1

Foti Dim
Foti Dim

Reputation: 1371

For me the carthage update build phase was causing the issue.

Also check if you have any other build phases with scripts that modify files or code.

Upvotes: 1

Olie
Olie

Reputation: 24675

First: +1 on ConfusedNoob's answer, because that was the problem (which led me to numerous experiments and finally this solution.) If my answer helps you, +1 his, too, because his hint was huge!

(Also, see my other answer, below, that bypasses agvtool altogether. I eventually settled-in to using that in all my projects.)

I've been messing with it a bit and the only thing I've found that works reliably to solve it is to use agvtool as a pre-action in the appropriate scheme(s), rather than as a run-script in the build-phases.

  • CMD-SHIFT-comma to edit schemes (XCode 6.x)
  • Twiddle-open whichever scheme you want this on. I did it on Run and Archive, but I probably only really need it on archive.
  • Select the "+" icon and "New run script action"
  • Add your agvtool script. If you care, mine is:

    cd ${PROJECT_DIR} ; xcrun agvtool next-version -all
    

(NOTE: pre-actions don't naturally run in ${PROJECT_DIR}, so you have to cd.)

Close & save and that's it.

The problem is that agvtool modifies the project file (unnecessarily, since all the build numbers we care about are elsewhere), and modifying the project file causes the build to cancel.

+1 one on the question, too -- cripes, that was a tough one!

Upvotes: 33

Olie
Olie

Reputation: 24675

Another technique is to skip agvtool altogether. Just add this runtime script to the end of your build phases (after copy bundle resources.)

  • Select your project

Select your project

  • Select build phases and +

Select build phases and +

  • Add a new Run Script phase

Add new run-script phase

  • Enter the script

Enter the script

The script, for easy copy/paste:

buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

Make sure your script runs after the copy-bundle phases of your build

Upvotes: 3

ConfusedNoob
ConfusedNoob

Reputation: 10186

Do you have a custom Run Script that bumps the version with agvtool? I found this to cause this exact behavior. Almost 100% failure to archive, and common failure to build. Removing this fixed the issue for me.

Upvotes: 59

Related Questions