Tuesday, August 24, 2010

Tip of the Day: How to Zip your App

One thing I have found rather glossed over in the development of iPhone Applications is the format used to upload your app.  Currently, there is an program you can download from iTunes Connect called the Application Loader.  The Application Loader directly connects you to the iTunes Connect site and allows you to upload any App for which you have already created a profile.  So assuming you've created your application profile and just need to upload the binary, you are now faced with a rather mysterious problem.  When you open Application Loader and set up your connection, you are presented with a file dialog to select the binary.  The only problem is that nothing in your development folder is acceptable to this application.  Not any application, be it debug, release or distribution, no library, no file; it's all grayed out.  What's a developer to do?

The answer is quite simple: Zip It.  However, you can't just zip the file.  As far as I know, there is no GUI tool on the Macintosh that can zip application binaries. 

Thanks to aeldron this has become much simpler for you, my fellow developer.  Simply open Finder and navigate to your application's development directory.  From there, you want to find your application, which should be in the directory build/Distribution-iphoneos.  Next, right-click / control-click / two-fingered-click on the file[1] YourAppName.app, replacing YourAppName with the name of your App.  In the pop-up / context menu that appears, select Compress and a corresponding YourAppName.zip should be created.

Now, when you start Application Loader you will see your zip file in black in your build/Distribution-iphoneos directory and you will be able to select it for upload.  Hooray, now the long and nervous wait: will they accept my App?

Or do it via the command line


If you feel you're a hard-core developer who want to get her hands on every aspect of how things work, you can still simply resort to the command line, but here's where things get tricky.  I'll assume you, the reader, know how to execute the Terminal program typically found in /Applications/Utilities/Terminal.app and how to change directory (hint: cd) to the directory containing your project.  I'll therefore assume you're in your project directory.  I'll make one more assumption here: that your binary is located in the folder Distribution-iphoneos; this should be typical if you followed most guides for building your iPhone App and I hope to have a guide to this at a later date.

So, to zip up your binary, type the following commands:
cd build/Distribution-iphoneos
zip -yr ../../YourAppName.zip YourAppName.app
replacing YourAppName with the name of your App.  This puts a file called YourAppName.zip in your project's root folder.  Now, when you start Application Loader you will see your zip file in black and you will be able to select it for upload.  Hooray, now the long and nervous wait: will they accept my App?

One final note for you, my fellow iPhone Application Developer: be very careful to include both the y and r parameters to your zip command line.  r causes zip to include all the files within your application, using recursion to encapsulate everything within.  y on the other hand is much more subtle.  Without y, zip will translate every symbolic link into a copy of the thing to which it points.  Since your application contains symbolic links, this is significant since iTunes Connect needs those to remain links and not be replaced with solid copies.  Thus, the y is necessary for to keep your application in the format expected by iTunes Connect and required by the Application Loader.

See, I told you it wasn't obvious!
-----
[1]Technically, the .app entry is a directory, but appears as a file in Finder; you can see this directory's contents by right-click / control-click / two-fingered-click it and selecting Show Contents from the context menu.

2 comments:

  1. You don't need to use the command line to zip a file on a Mac. Just select the file(s) you want to zip and right-click (or ctrl+left click) and select "Compress " from the context menu.

    ReplyDelete
  2. Thanks, aeldron! I've updated the post based on your very helpful advice! Much obliged!

    ReplyDelete