Installing Beta Builds on iPhone

Probably the hardest part of learning to code an iPhone app is figuring out how to get your app installed on a phone. Even after you’ve installed your app on your personal development phone, installing it on other people’s phones for beta testing is especially tricky.

Here’s the rough outline:

  1. Create an “Ad Hoc” Provisioning Profile (a .mobileprovision file) for beta testing.
  2. Find yourself a friendly beta tester.
  3. Each beta tester needs to give you the Universal Device Identifier (UDID) of his/her device. (This number is not easily visible to users.)
  4. Submit the UDID as a named “Device” to Apple.
  5. Attach the device to your Provisioning Profile. Apple will generate (or regenerate) a .mobileprovision file for you to download. Always use the latest .mobileprovision file.
  6. Build (or rebuild) your software in Xcode using the latest Provisioning Profile.
  7. Zip up your application.
  8. Deliver your finished .app together with the .mobileprovision to your beta tester.
  9. The beta tester installs your provisioning profile, either by dragging it into iTunes or by using the iPhone Configuration Utility (iPCU).
  10. Finally, the beta tester installs your app, using either iTunes or iPCU.

That’s a lot of steps; there’s a lot of room for things to go wrong. Here’s a few gotchas we encountered on our way to releasing the Redfin iPhone app.

Some Zip Tools Don’t Work; Use ditto

Zipping your .app file is surprisingly tricky business. For example, if you use Apache Ant’s <zip> task to create your zipfile, it will ignore the UNIX permissions of the files it zips. When unsuspecting beta testers try to extract the app, they’ll find that it installs successfully under Windows (which doesn’t honor UNIX permissions) but if they install from OS X, the app will immediately crash on startup, with no crash log.

FYI, if you observe this permissions crash via the device console logs, it looks a little like this:

Tue Sep 29 17:47:04 unknown com.apple.launchd[1] : (UIKitApplication:com.redfin.redfin[0x43d3]) posix_spawn("/var/mobile/Applications/2B5E0CE3-362F-4FF0-80A2-C45DE3923C86/Redfin.app/Redfin", ...): Permission denied
Tue Sep 29 17:47:04 unknown com.apple.launchd[1] : (UIKitApplication:com.redfin.redfin[0x43d3]) Exited with exit code: 1
Tue Sep 29 17:47:04 unknown SpringBoard[24] : Failed to spawn Redfin. Unable to obtain a task name port right for pid 13432: (os/kern) failure
Tue Sep 29 17:47:04 unknown com.apple.launchd[1] : (UIKitApplication:com.redfin.redfin[0x43d3]) Throttling respawn: Will start in 2147483647 seconds
Tue Sep 29 17:47:04 unknown SpringBoard[24] : Application 'Redfin' exited abnormally with exit status 1

(Please excuse the scrolling; WordPress automatically screws up this log file entry.)

Even the standard command-line zip tool from Info-ZIP that comes with OS X doesn’t quite do the job. Insidiously, zip archives created with zip work fine for beta testing, but the App Store will reject them, claiming that the app signature is invalid.

You can check the validity of your app signature with codesign -vvvv YourAppName.app. (Yes, all four “v”s are necessary.) Valid apps should look like this:

$ codesign -vvvv Redfin.app
Redfin.app: valid on disk
Redfin.app: satisfies its Designated Requirement

It is very easy to disturb this signature. For example, if you copy the app with cp -r Redfin.app /tmp and then check the signature, you’ll get a message like this:

$ codesign -vvvv Redfin.app
Redfin.app: a sealed resource is missing or invalid
/private/tmp/Redfin.app/CodeResources: resource added

Unfortunately, cp isn’t the only command-line tool that can invalidate the signature. If you create your zip archive using zip -r yourappname YourAppName.app and then unzip it (either with Finder or with unzip), you’ll invalidate the signature.

You don’t get this problem if you use Finder to create the zip archive, by putting YourAppName.app in a folder called YourAppName, and right-clicking on the YourAppName folder and selecting the “Compress” option. To duplicate this functionality automatically, you’ll have to use ditto, which comes with OS X. ditto -c -k YourAppName YourAppName.zip should do the trick.

Don’t Use iTunes; Use the iPhone Configuration Utility

Some people are able to successfully install apps and provisioning profiles using iTunes; if iTunes works for you, great. But a lot of our beta testers weren’t so lucky. iTunes would often fail mysteriously, sometimes with no useful error messages.

The iPhone Configuration Utility (iPCU) allows users to generate log files with error messages; these error messages are critical for diagnosing problems with application installation. More generally, iPCU includes better error messages than iTunes all around; in many cases, switching to iPCU gave our beta testers enough information to solve the problem without the aid of developers.

There’s another good reason to use iPCU instead of iTunes for app installation: you can sync an iPhone with only one iTunes machine. If you want to install beta apps using any other machine, you have to use the iPhone Configuration Utility. In most cases, you can workaround even the trickiest app installation problems just by using iPCU to install from another machine.

To install an app using iPCU:

  1. Download and install the iPhone Configuration Utility from Apple.
  2. Connect your iPhone/iPod to your computer via USB cable.
  3. Close iTunes, if it is open, before launching iPCU
  4. Launch iPCU. You should see your device appear in the “Devices” section on the left side of the window.
  5. Add the provisioning profile (mobile provision) to the iPCU Library: Click on “Provisioning Profiles”, then drag the .mobileprovision file into the Provisioning Profiles pane.
  6. Add the application to the iPCU Library: Click on “Applications”, then drag the app into the Applications Pane. On Windows, the app will be a folder, named something like YourAppName.app. On Mac OS X, the app will be a single application file.
  7. Access your device: Click on your device in the list of devices on the left. You should see five tabs appear in the main window: “Summary”, “Configuration Profiles”, “Provisioning Profiles”, “Applications”, and “Console”.
  8. Install the Provisioning Profile: Click on the “Provisioning Profiles” tab of your device. You should see your Ad Hoc Provisioning Profile in the list of profiles. In the “Install” column you should see either a button that says “Install” or a button that says “Remove” (if you’ve installed this profile previously).
  9. Install the app: Click on your device’s “Applications” tab. You should see your app in the list of applications. In the “Install” column you should see either a button that says “Install” or a button that says “Uninstall” (if you’ve already installed the app).

That’s all there is to it, assuming that nothing goes wrong.

Error Messages: What Could Go Wrong?

  • iPhone Config Utility: “Could not start session with device. Error: kAMDSessionActiveError

    Your device has turned off / fallen asleep. Push the power button, slide to unlock, and try it again.

  • iPhone Config Utility: I tried to install, and I got an error like “Could not install application on device. Error: -402620395.”.

    This is almost certainly because the .mobileprovision didn’t install correctly. Clear out all provisioning profiles from your phone and from the iPCU Library (following directions above), drag your .mobileprovision file into the Library / Provisioning Profiles section, then click on Devices / Your Device / Provisioning Profiles. Make sure you see only one profile on the list, and make sure it’s installed.

  • iPhone Config Utility: I tried to install, and I got an error like “Could not install application on device. Error: -402620393.”.

    We saw this error several times but never figured out the root cause. Installing from another machine worked around the problem.

  • iPhone Config Utility: I tried to install, and I got an error like “Could not transfer application to device. Error: kAMDUndefinedError.”.

    A number of our beta users had this error, but we never deduced the root cause. In at least one case, re-installing the latest version of iPCU resolved the problem. In all known cases, installing from another machine worked around the problem.

  • iTunes: I tried to sync, and I got an error like “The application ‘YourAppName’ was not installed on the iPhone because an unknown error occurred (0xE8008017).”

    This is the same as error -402620393 above. (Note that E8008017 is hexadecimal for the signed integer -402620393.) We saw this error several times but never figured out the root cause. Installing from another machine without iTunes (using iPCU) worked around the problem.

  • iTunes: I tried to sync, and I got an error like “The application ‘YourAppName’ was not installed on the iPhone because an unknown error occurred (0xE8008015).”

    This is the same as error -402620395 above. (Note that E8008015 is hexadecimal for the signed integer -402620395.)This is almost certainly because the .mobileprovision didn’t install correctly. Try dragging the .mobileprovision again to Applications pane in iTunes and syncing. It might also help to delete all of your existing mobile provisions (see Clear Out the Phone Using the Phone below).

Troubleshooting

Still not working? Try this.

  1. Using iTunes? Try the iPhone Configuration Utility.
  2. Try installing from another machine. It’s often especially helpful to try installing from a Mac if you’re failing on Windows, or to try installing from a Windows box if you’re failing on a Mac. (If you’re on Windows and you don’t have access to a Mac, try switching to a Windows machine that does not have iTunes installed.)
  3. Close iTunes. The iPhone Configuration Utility doesn’t work so well if iTunes is open. Note that iTunes auto-launches by default when you plug in an iPhone/iPod.
  4. Try restarting your phone. Press and hold the power button at the top of the phone, slide to power off. Wait until the screen turns off, then press and hold the power button again to start it up again. No, seriously. This actually works, more often than you’d think.
  5. Clear out the app and provisioning profiles correctly, as described below.
  6. Delete your entire iPCU Library, as described below.
  7. Using iPhone Configuration Utility? Try iTunes.
  8. Still not working? Examine the iPCU Log. Directions below.

Clear Out the Phone Using the Phone

Both iTunes and iPCU provide the ability to remove apps and provisioning profiles from the phone, but they don’t work very reliably, especially when you have multiple versions of the same app/profile bouncing around.

The most reliable way to remove an app from the iPhone is to do it the normal way: on the Home screen, press and hold your finger on the app; an X will appear. Tap on the X to delete the app.

You can remove provisioning profiles using the iPhone “Settings” app. In the “General” section, scroll down to the “Profiles” section, select it, tap on the old provisioning profile, and tap “Remove”. (Ordinarily you shouldn’t need to delete provisioning profiles, but the best way to be sure that you’ve installed a .mobileprovision file is to remove all profiles and then install just the provision you need.)

profiles

Deleting the iPhone Configuration Utility Library

Removing the app and provisioning profile from your iPCU library should just be a simple matter of deleting them in iPCU. But if something goes really wrong, you may have to purge the iPCU library. (In at least one recorded case, purging the iPCU library not only fixed iPCU, but also fixed installing the app via iTunes.)

On OSX, the iPCU library is stored in your Home directory, in ./Library/MobileDevice. You can delete the entire folder.

On Windows, the library is stored in your local application data folder. To find your local app data folder:

  • On Vista, press the Windows key, type %localappdata% in the search box, and press Enter.

  • On XP, press the Windows key, select “Run” and type %userprofile%Local SettingsApplication Data

Go to the “Apple Computer” folder. (There may also be an “Apple” folder and an “Apple_Inc” folder; ignore those.) You should see an “iPhone Configuration Utility” folder here and a “MobileDevice” folder here; delete both of them.

Extracting the iPCU Log

To access your device console, click on your device in the “Devices” section on the left pane of iPCU. There is a “Console” tab on the far right side. Click on that and you should start seeing console messages. (It sometimes takes a few seconds for the messages to appear.) You can click “Save Log As…” to generate a text file that you can send out as an attachment.

Discussion

  • http://blog.redfin.com/ Glenn Kelman

    Man, Dan, I feel like I just got smarter. Great post. If I were still single, I feel like the information in here could somehow help me pick up women at parties. It’s that good…

  • Pingback: Tweets that mention Installing Beta Builds on iPhone | Redfin Developers’ Blog, Installing Beta Builds on iPhone | Redfin Developers’ Blog -- Topsy.com

  • Pingback: Tips for iPhone Ad Hoc Beta Testing | Recess Blog

  • http://vmac.ch Chris

    That was just the information I was searching for. Thanks for sharing it.

  • http://www.digitalspark.us James Morris

    The application ‘YourAppName’ was not installed on the iPhone because an unknown error occurred (0xE8008017)

    My customer just got this error trying to install on PC. Turns out there were “alias” files in the .app folder that matched the names of other folders. Those alias files were preventing the folder from being extracted. Specifically, we included a folder called “data” there was also a “data” file that was simply an alias to the folder. Windows was hating that.
    Opened up the zip file on a PC, moved all the good files into a new folder, archived it on the PC, then sent that over. Everything worked.

  • Pingback: Tips for iPhone Ad Hoc Beta Testing | Recess Mobile Blog

  • Martin

    I got a “Could not transfer application to device. Error:” message (note the empty message after “Error”) in iPhone Configuration Utility when trying to install a beta build of an app we’ve had someone develop. Tried iTunes instead, that worked.

  • http://twitter.com/ben_bar Ben Baroukh

    I am affected by the “kAMDUndefined error” problem. I am on the latest version of the IpCU. Tried on two different machines, nothing… If anyone have some updated info on this, it would be much appreciated.

  • Pingback: Levysoft » Come rimuovere un Profilo di Fornitura (Ad Hoc Provisioning Profile) da iPhone e iTunes su Mac OS X e Windows

  • Casemon

    Getting a seg fault on launch; splash shows but then repeatedly an error mentioning this:

    error: ::task_for_pid ( target_tport = 0×0103, pid = 304, task => 0×0000 ) 0x000001f5/0x000001f5 0x000001f5/0x000001f5 err = (os/kern) failure (0×00000005)

    No idea how to debug this, as it tells me… not much at all! This page was recommended, but didn't see anything related to the above.

    Any ideas?

  • Bcrain

    I haven't had iPCU work in a LONG time. I always get “Could not install application on device. Error: kAMDReceiveMessageError” I have never been able to fix this issue.

    The console log states nothing new when this happens. I have uninstalled and reinstalled iPCU. I have cleared the library several times. I have restarted the phones. I have tried on 4 different iPhones. I have tried on 3 different computers.

    Does ANYONE have any idea on this issues?

    Thanks!

  • Miyagi Chan

    Great post, IPCU worked for me.

    I did tried to drag my ah-hoc.app to itune with the provision file, but no icon shown in itune, ah-hoc installation fail.

    but in IPCU, it works and much more easier.  Thanks

  • Josh Corey

    If you are receiving the “kamdreceivemessageerror” error, are you installing from Windows?  The addition of UIRequiredDeviceCapabilities to the Info.plist in an App for some reason doesn't work with the Windows version of ICU.  Try using ICU on a Mac if you have access to one, everything should go smoothly then…