Friday, October 23, 2009

Automated Zipping in Xcode

I like to automate everything. I'm a firm believer in the "one-click, build-all, distribute-all" type of solution.

Per Apple's recommendations, after you generate your .app file, you need to compress it by right clicking on the file and selecting, conveniently enough, "Compress." Not exactly automated. After doing some searching, I found this little gem:
  • ditto -c -k --sequesterRsrc --keepParent "$PRODUCT_NAME.app" "$PRODUCT_NAME$revnum.zip"
Which, when I ran it on the command line (with $PRODUCT_NAME appropriately filled in), generated a perfectly acceptable zip file that I could submit to itunesconnect. But when I put the same command in my post-build script, I got an invalid zip file that itunesconnect would not accept. Ouch! The two files had different sizes; I'm really not sure what could have caused the problem (something in the bash shell, maybe?)

Luckily, I found an alternate gem:
  • zip -r -T -y "$PRODUCT_NAME$revnum.zip" "$PRODUCT_NAME.app"
Now, I originally tried using zip before and it didn't work. the '-y' option is the key, as it preserves the symlinks. I won't pretend to understand exactly why that makes the difference, but the script does indeed now generate a valid zip file. Fantastic!

No comments: