Friday, July 22, 2011

Installing Xcode 3.2.6 in Mac OS X Lion (10.7)

Apple has decided to only ship Xcode 4.1 for Mac OS X Lion and disallow any earlier versions. Unfortunately this limits the resulting binaries to Intel macs and the Mac OS X 10.6 SDK. Developers that are still interested in supporting PowerPC Macs and/or Mac OS X 10.4 / 10.5 are left behind.

So here's a quick script that you can use to install Xcode 3.2.6 on Lion:
 Install Xcode 3.2.6 on Lion.command
Just extract the zip file, put the resulting script file, 'Install Xcode 3.2.6 on Lion.command' in the same directory as the downloaded disk image 'xcode_3.2.6_and_ios_sdk_4.3.dmg' and double-click 'Install Xcode 3.2.6 on Lion.command'.

Also, here are step-by-step instructions in case the script above doesn't work for you:


  1. Download the Xcode 3.2.6 disk image, 'xcode_3.2.6_and_ios_sdk_4.3.dmg', (I will assume it's in ~/Downloads for the next steps).

  2. Open up the Terminal and change to the directory where the image resides:
    cd ~/Downloads

  3. Attach the disk image with a shadow image to make it writable. Terminal command (as one line):
    hdiutil attach -shadow xcode_3.2.6_and_ios_sdk_4.3.shadow xcode_3.2.6_and_ios_sdk_4.3.dmg

  4. Remove the string '&& system.compareVersions(my.target.systemVersion.ProductVersion, '10.7') < 0 ' from line 148 in 'Xcode and iOS SDK.mpkg/Contents/iPhoneSDKSL.dist'. Assuming the disk image got mounted at '/Volumes/Xcode and iOS SDK', you can use this one-liner:
    cat '/Volumes/Xcode and iOS SDK/Xcode and iOS SDK.mpkg/Contents/iPhoneSDKSL.dist' | sed "s/&& system.compareVersions(my.target.systemVersion.ProductVersion, '10.7') < 0 //g" > '/Volumes/Xcode and iOS SDK/Xcode and iOS SDK.mpkg/Contents/iPhoneSDKSL.dist.new' && mv '/Volumes/Xcode and iOS SDK/Xcode and iOS SDK.mpkg/Contents/iPhoneSDKSL.dist.new' '/Volumes/Xcode and iOS SDK/Xcode and iOS SDK.mpkg/Contents/iPhoneSDKSL.dist'

  5. Install Xcode!

You can install Xcode 4.1 and Xcode 3.2.6 side-by-side, by choosing a different directory than '/Developer' as the install target for Xcode 3.2.6 (I use '/Xcode3.2'). However you can only have one global set of development tools installed (the ones that are installed in '/usr', i.e. are available for command line development).

Update: Xcode 3.2.6 can also be installed in Mountain Lion, but one very important point is to uncheck "System Tools" when installing. "System Tools" contain kernel extensions for profiling which are incompatible with the Mountain Lion kernel and will cause the system to panic on startup.
In addition, you will probably want to remove the kext AppleProfileFamily.kext in Mountain Lion because it cannot be loaded and causes annoying error messages on startup.