Home > Blog, iPhone > How to automatically build an IPA file from XCode

How to automatically build an IPA file from XCode

I have long since forgotten where I first read this, but I hope this will help an iPhone developer looking to simplify the process for sending their app to their user(s) via AdHoc.

Create a View-Based application project in xcode like so:

project_screenshot

I named mine HelloWorld ( How original!! ). After telling XCode where to store your project, you should be presented with a window similar to this:

heloworld

If you expand the Nib Files smart folder you should be presented with a window similar to this:

helloworldviewcontroller

If you named your project Hello World like I did, you should see a file called HelloWorldViewController.xib. Double click on HelloWorldViewController.xib to open the file in Interface Builder.

In Interface Builder, open up the Library ( Tools-> Library or Command-Shift-L) and Inspector  (Tools-> Inspector or Command-Shift-I) panels.  Drag over a UILabel and center in the view and change the text to HelloWorld by double clicking on the label and changing the text. You should have something similar to this:

interfacebuilder

You can close interface builder at this point. Going back to XCode, expand the Targets item and control-click ( or right click if using a multi button mouse ) and select Add->New Target and select “Other” at the bottom left and choose the Aggregate option similar to this:

aggregatetarget

And name the new target IPA:

ipa

On the next screen be sure the add HelloWord target as a direct dependency by clicking the plus button in the lower right corner under the Direct Dependencies section like this:

ipa_dependency

Close this window once you are done adding HelloWorld target as a direct dependency of IPA target. Right click or control-click on the IPA target and select the Add->New Build Phase->New Run Script Build Phase menu item and add the following code:

if [ $BUILD_STYLE != “AdHoc_Distribution” ]; then

exit

fi

# compress application.

/bin/mkdir $CONFIGURATION_BUILD_DIR/Payload

/bin/cp -R $CONFIGURATION_BUILD_DIR/HelloWorld.app $CONFIGURATION_BUILD_DIR/Payload

/bin/cp images/logo_itunes.png $CONFIGURATION_BUILD_DIR/iTunesArtwork

cd $CONFIGURATION_BUILD_DIR

# zip up the HelloWorld directory

/usr/bin/zip -r HelloWorld.ipa Payload iTunesArtwork

The run script window should look like this:

addrunscriptcode

Now you can choose to run the IPA target instead of the HelloWorld target to compile the application and turn it into HelloWorld.ipa file that your users can bring directly into iTunes simply by double clicking on it.

chooseipatarget

In the directory where you apps are built, you should find a file called HelloWorld.ipa:

debug-iphoneos

One last note: in the above script there are a few lines of code that will exit the shell script if the build configuration isn’t AdHoc_Distribution

if [ $BUILD_STYLE != “AdHoc_Distribution” ]; then

exit

fi

You actually don’t need these lines, I always create an AdHoc configuration that is used for sending out any betas to the testing group.  You can either create a build configuration call AdHoc_Distribution and make sure its selected before you build, or just remove the code ( three lines ) altogether.  You can download the complete project here http://files.idotcom.us/HelloWorld_IPA.zip

If you are having problems installing your adhoc application via iTunes, check that the distribution profile that you are using has the correct device and that you have a dist.plist file in your XCode project with the following contents:

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”&gt;

<plist version=”1.0″>

<dict>

<key>get-task-allow</key>

<false/>

</dict>

</plist>

Advertisements
Categories: Blog, iPhone Tags:
  1. May 29, 2009 at 1:43 am

    Onload of page my antivirus put alert, check pls.
    Have a nice day

  2. June 5, 2009 at 3:25 am

    Hi there,
    Thanks for article. Everytime like to read you.
    Thanks
    SonyaSunny

  3. June 13, 2009 at 10:37 pm

    Hi, gr8 post thanks for posting. Information is useful!

  4. June 15, 2009 at 10:09 am

    The best information i have found exactly here. Keep going Thank you

  5. July 6, 2009 at 7:54 pm

    How soon will you update your blog? I’m interested in reading some more information on this issue.

    • Hasani Hunter
      August 13, 2009 at 6:39 pm

      I will update more often thanks for reading!!

  6. August 7, 2009 at 3:22 pm

    Thanks,; thanks, thanks, thanks a million… You just saved me a lot of time !

  7. Levente
    August 10, 2009 at 12:47 pm

    help !! I downloaded your complete project, and ther is an error :

    ” Code Sign error: The identity ‘iPhone Developer’ doesn’t match any vaild certificate/private key pair in the default keychain”

    what can i do ?

    thanks a lot.

    • Hasani Hunter
      August 13, 2009 at 6:38 pm

      I have disabled code signing for this sample project so you should be able to create the IPA

  8. jack
    August 13, 2009 at 5:59 pm

    it didnt work for me.
    it didnt build the .ipa file
    i did exactly wat it said to do.

    • Hasani Hunter
      August 13, 2009 at 6:37 pm

      Please check out the new zip file attached to this post. Thanks!

  9. Hasani Hunter
    August 13, 2009 at 6:37 pm

    Thanks for all of your comments! I have uploaded a new version which should build the IPA correctly.

  10. August 15, 2009 at 11:15 pm

    Thank you so much for providing this article, it’s great to finally find something worth reading.

    http://www.workingforgoogle.com

  11. gumbypp
    August 19, 2009 at 12:48 am

    This script works great, but doesn’t take into account the possible deletion of resources between builds – if this happens the Payload inside of the IPA file will contain stale unsigned resource(s) yielding the dreaded 0xE8008017 error when installing the IPA via iTunes. The fix is to add a new line with “/bin/rm -rf $CONFIGURATION_BUILD_DIR/Payload” before the mkdir line and “rm HelloWorld.ipa” before the zip line.

  12. Manish Agrawal
    September 1, 2009 at 7:34 am

    @Hasani

    Can you just tell me how to disable the code signing for any project.

    Thanks
    Manish

  13. abdelahad
    October 1, 2009 at 3:14 am

    i have error said

    1.”cp” no such directory

    2.code signing error

  14. Mike
    November 4, 2009 at 3:03 pm

    Sorry, i can’t see the images. Please check. Thank you very much.

  15. November 9, 2009 at 7:31 pm

    Hi, can I build an application without signing or using certificate? If I can please describe it in more details. thank you

    • January 5, 2010 at 1:34 pm

      You can build an application without using a certificate.. You will just be able to run it in the iPhone Simulator

  16. Omnipotency
    November 13, 2009 at 5:02 pm

    The evil “Code Sign error: The identity ‘iPhone Developer’ doesn’t match any vaild certificate/private key pair in the default keychain” error came for me also.

    BTW, I’m using Xcode 3.2 for Snow Leopard. Plz help!!!

  17. Omnipotency
    November 13, 2009 at 5:10 pm

    O Ya, I forgot, the download isn’t a link or… anything.

    Sry about the DP

  18. Robert
    November 15, 2009 at 5:02 am

    Thanks! This is exactly what I was looking for. I made some improvements to make the script completely generic:

    payload_dir=”$CONFIGURATION_BUILD_DIR/Payload”
    app_bundle_dir=”$CONFIGURATION_BUILD_DIR/${PROJECT_NAME}.app”

    /bin/rm -rf “$payload_dir”
    /bin/mkdir “$payload_dir”
    /bin/cp -R “$app_bundle_dir” “$payload_dir”
    /bin/cp iTunesArtwork “$CONFIGURATION_BUILD_DIR/iTunesArtwork”
    cd “$CONFIGURATION_BUILD_DIR”

    /usr/bin/zip -r “${PROJECT_NAME}.ipa” Payload iTunesArtwork
    rm -rf “$payload_dir” iTunesArtwork

    I also added $(CONFIGURATION_BUILD_DIR)/$(PROJECT_NAME).app as an input file in the configuration window, and added $(CONFIGURATION_BUILD_DIR)/$(PROJECT_NAME).ipa as an output file so that the build systems knows that the ipa needs to be rebuilt if the app dir is newer.

    • January 5, 2010 at 1:36 pm

      That is a very nice improvement.. Too bad I didn’t think of that!! I’m wondering if that can be used as a XCode template?

  19. KP fu
    November 15, 2009 at 11:36 am

    the ipa file is not showing up can you please help me

  20. November 16, 2009 at 11:26 am

    @Hasani Hunter

    Hey man, i didn’t found the new zip on the post!

    Can you put the link again? Tks a lot.

  21. Tasos
    January 2, 2010 at 5:23 pm

    Where is the zip file??

    • January 5, 2010 at 1:23 pm

      I recently moved the blog to wordpress and forgot to update the download link appropriately.. The post has been updated with the download link.

  22. J Alex Antony Vijay
    January 5, 2010 at 11:55 am

    Hi,

    I am new for iPhone dev. I created an web application for iPhone using iPhone SDK.
    I generated ipa file for my project.
    When i install my project on iPhone using iTune, i am getting following error msg
    The application “checknumber” was not installed on the iPhone “jfalexvijay” because an unknown error occured (0xE800800E).

    Please any one help me…
    Regards,
    J Alex Antony Vijay.

    • January 5, 2010 at 1:25 pm

      I would check that your distribution profile has the correct device “jfalexvijay” and make sure that you have a dist.plist in your XCode project.

  23. January 23, 2010 at 1:25 pm

    Thank you so much! This was the exact information that I was searching for. You’ll go to heaven 😀

  1. June 23, 2009 at 9:29 am
  2. August 10, 2009 at 9:13 am
  3. September 30, 2009 at 9:01 am
  4. October 13, 2009 at 8:14 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: