Wednesday 21 September 2011

iOS: Using older SDKs with newer Xcode versions

When you update Xcode versions, the installer automatically removes any old SDKs you have lying around, and replaces them with the latest version.

This is fine behaviour, as the most recent SDKs remain backwards compatible. You can set your project to target older iOS versions. If you do this, the newer SDK features are disabled for you.

However, there are times when you need to use an older SDK.

For example, I am running the latest Xcode with a beta iOS 5 SDK installed. Since this was originally installed on a clean machine, I didn't set the beta install to use a parallel directory and leave the "release version" of the developer tools intact - they simply weren't installed. (Making a parallel install is, in general, the best practice when installing a beta Xcode/SDK set).

Fear not. You can still get your newer Xcode to build with an older SDK, without downgrading your Xcode or making a parallel install:


  • Close any running Xcode instance you have open.
  • Locate the install DMG for an old version of Xcode (e.g. Xcode_3.2.5_and_ios_sdk_4.2_final.dmg, they name them so well) and open it.
  • Do not run the installer!
  • Open the Packages directory in that disk image. It is a hidden directory. Try this terminal incantation: "open /Volumes/Xcode\ and\ iOS\ SDK/Packages"
  • Locate the iPhoneOS and iPhoneSimulator SDKs for the version you want. Run just those pkg files. (e.g. I ran the iPhoneSDK4_2.pkg and it's matching iPhoneSimulatorSDK4_2.pkg)
  • Make sure you specify the /Developer directory as your install location. If you don't, the SDKs will be installed in your root directory, under the /Platforms directory; you'll have to manually copy them into /Developer/Platforms yourself.
  • Now, re-open Xcode. If the SDKs installed in the right locations, they will be selectable in your project now.


8 comments:

andy said...

Just wanted to say 'thanks' for this brief tutorial. I'm running into some issues compiling my app against the 5.0 SDK, and I'm glad to see there's a way to compile against 4.3 other than installing a whole new copy of Xcode.

Anonymous said...

Thank you very much! Nice one!

But how would the same thing work with ancient iPhoneOS 3.1.3?

Pete Goodliffe said...

Can't say off hand, but I'd've guessed a similar technique is required.

Carsten said...

With Xcode 4.3.2 it does not seem to work to install the SDK and simulator into Developer, because Xcode 4.3.2 is installed into Applications folder when installed from App Store.

Any tips on this?

Pete Goodliffe said...

The latest "App Store" version of Xcode manages to exist as a single package by putting most of what was in the original /Developer directory within its own app bundle. (Some other, less used, parts are downloadable separately)

So, you can now find what was /Developer/Platforms in /Applications/Xcode.app/Contents/Developer/Platforms/

Carry on as before - but be aware that any modification you make within the Xcode directory will be overwritten when you upgrade Xcode.

It may be possible to install them in a parallel location (perhaps within ~/Library. I have not investigated this)

Carsten said...

Appreciate your prompt reply.

When installing SDK and simulator I am unable to select /Applications/Xcode.app/Contents/Developer/Platforms/ as install location in the installation program.

Instead I tried to install to /Developer and afterwards manually copy /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/ to /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/ but Xcode.app is write protected and I can't remove that write protection.

Pete Goodliffe said...

Surely sudo is your friend?

Carsten said...

I managed to remove the write protection through Finder. That made a difference.

sudo is not my best friend... :-)