Thursday, July 8, 2010

Building from terminal with more than one Xcode version

It's possible to build against more than one Xcode version from terminal.
First step is to install Xcode versions alongside each other instead of as an Update. When you download the latest Xcode from Apple, just choose to install to a directory that's parallel to your current Xcode install. In this case we had Xcode 3.2.2 installed in the /Developer directory, so I installed Xcode 3.2.3 in a directory named /Developer323.
One of the tricky things I ran into after the 3.2.3 install was that it defaulted to this for all builds. I found this out when I tried to build existing iPhoneOS 3.1.3 builds and got the error:

=== BUILD NATIVE TARGET Mobile OF PROJECT Mobile WITH CONFIGURATION Release ===Check dependencies
No architectures to compile for (ARCHS=, VALID_ARCHS=i386 ppc ppc64 ppc7400 ppc970 x86_64).
[BEROR]No architectures to compile for (ARCHS=, VALID_ARCHS=i386 ppc ppc64 ppc7400 ppc970 x86_64).

Since we actually wanted to use 3.2.2 as the default I needed to know how to set this from terminal.
Apple gives several options for calling Xcode version from terminal:
http://developer.apple.com/mac/library/documentation/Xcode/Conceptual/XcodeCoexistence/Contents/Resources/en.lproj/Details/Details.html

Since the installs are sitting in parallel it became as easy as adding this line before the xcodebuild section in the build:
export DEVELOPER_DIR="/Developer"
and when we're ready to build iPhoneOS4 against 3.2.3 this line will become:
export DEVELOPER_DIR="/Developer323"

Android dx.bat causing out of memory errors

The Android SDK contains a file name dx.bat whose purpose is to convert class files to dex files. Embedded in the file is a JAVA_OPTS setting that is commented out by default.
When you build Android you may see an error like this:

-dex: [echo] Converting compiled files and external libraries into D:\Androidproject\bin\classes.dex...
[apply]
[apply] UNEXPECTED TOP-LEVEL ERROR:
[apply] java.lang.OutOfMemoryError: Java heap space....

First determine which SDK you are building against since all may be installed in the Android SDK location by default. In this case I see the failure:
BUILD FAILED
D:\ProgramFiles\Java\android-sdk-windows\platforms\android-1.6...

You need to edit the dx.bat file that sits in the tools directory for the SDK you're using (ex. D:\ProgramFiles\Java\android-sdk-windows\platforms\android-1.6\tools). There's a 'set javaOpts=' setting that has no value by default, and below in the file a commented section with the value set to -Xmx256M. Either remove the comment from the commented one, or add the value to the empty one.

Friday, July 2, 2010

Hudson connectivity issues with security enabled

We ran into issues with Hudson dropping off connections to slaves once security was enabled on the Hudson server.
We took the following steps to reconnect the servers as a Windows service and they have remained connected with no issues so far:
Verify that the node has Hudson Slave installed as a service. If not, or if the validity of the installed one is in question, follow these steps. Otherwise skip to step g:
a. Configure the node as jnlp on the main Hudson server.
b. Login to the slave machine and open a browser
c. Paste the URL from the jnlp configuration into a browser in the node (ex. http://servername/hudson/computer/slavename/slave-agent.jnlp)
d. If the 'Connected' page doesn't come up, you may need to add the URL to the 'Trusted Sites' in IE security configuration
e.The 'Connected' browser window will have a 'File' - 'Install as a Windows Service' option. Choose this.
f. After installed, stop the Hudson Slave service. Change the login to an account with rights to run the slave service
g. Open the hudson-slave.xml in the Hudson home directory on the slave machine, usually someplace like D:\Hudson
h. In the line with the jnlp URL, add the following after the URL: -jnlpCredentials hudsonusername:password (an account they you have configured in your Hudson security setup)
i. In the Hudson UI, change the slave configuration to use Windows service to connect. Enter user with password as the account to connect.
j. Start the Hudson Slave service on the slave and make sure it's set to 'Automatic' for startup

Tuesday, June 15, 2010

iPhone/iPad arguments from terminal for Hudson

When we started building iPad I realized some of the existing iPhone builds had possibly been calling values like SDKROOT incorrectly, but since there was only one sdk installed it failed silently and fell back to the default sdk. But building iPad and iPhone there's a need to call these values out correctly. From the Apple site, requirements are (quoting):

"To configure Universal apps that run on both iPad and iPhone, in Build Settings:
- set Base SDK in the Architectures section to “iPhone SDK 3.2”
- set iPhone OS Deployment Target to iPhone OS 3.1.3 or earlier
• For iPad-only development, use iPhone SDK 3.2 and target iPhone OS 3.2
• For iPhone-only, use iPhone SDK 3.1.3 and target iPhone OS 3.1.3 or earlier
• Be sure to set Targeted Device Family to iPad, iPhone, or iPhone/iPad"

But what are those values from terminal so we can pass them with Hudson?
Since we aren't building a universal app we currently have this configured in the iPhone build:
SDKROOT=iphoneos3.1.3 IPHONEOS_DEPLOYMENT_TARGET=3.1.3 TARGETED_DEVICE_FAMILY=1
and this in the iPad:
SDKROOT=iphoneos3.2 IPHONEOS_DEPLOYMENT_TARGET=3.2 TARGETED_DEVICE_FAMILY=2

Tuesday, June 8, 2010

iPhone Distribution code signing from Hudson

iPhone code signing for Distribution is a task in itself, but when adding in the need to do it in a hands off way it gets even more complex.
1) First you want to create and download a Distribution profile to your build machine and install in the correct spot. This is a whole topic in itself and I might create a separate post on this.
2) Open the xcodeproj for the build you want to create in Xcode.
3) Click on the Project name and then click on the Info icon at the top of the Xcode window.
4) This opens the Project Info window, then click on the Configurations tab.
5) Click on your Release build (if you don't have one yet, create one), and then choose the Duplicate button at the bottom of the window
6) Name the new Configuration 'Distribution'
7) Go back to the Configurations tab in the Project Info window and scroll down to find the Code Signing Identity choice
8) Click on the Value drop down and choose the Distribution profile for the Code Signing Identity. You can then close the Project Info window
9) The important point now!!: if you don't have version control save of the xcodeproj location to a safe backup location. If you have version control, check the xcodeproj location back in. What you should see is that the pbxproj file has changed and has been updated with the Distribution profile
10) From a Hudson build you can now call the build using this pbxproj and use '-configuration Distribution' in the xcodebuild line, and you'll have a Distribution build created!

Friday, May 28, 2010

Hudson Android builds pt 1

Android builds from Hudson are challenging in a completely different way than the iPhone builds. The challenges are mainly centered around updating the Android manifest file (which is owned by the Android development team, not the team doing the builds). So we need to dynamically load and change this file from version control before we build.

1. The svn control and tagging from Hudson is handled in the same way as the iPhone builds (see Hudson iPhone builds pt. 1)

2. Since we need to update the Android manifest file for each build, we need a build.xml that is different than a development build.xml and can handle the manifest update steps. The way we're handling this now is by taking the developer build.xml (which was originally created by the build team) and adding or ANT replace targets to it. We then overwrite the existing build.xml with this one every time.
There's a possible issue here in that the developers could alter the build.xml, and we'd need to handle it dynamically also (do the same thing that we're doing for the manifest). In that case it should be possible to create an ANT build.xml to alter the Android build.xml every run. But for now our first step is to just copy over the altered build.xml and overwrite the dev one:

xcopy /y/q "D:\Property_files\Android_trunk\build.bak4" D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk\build.xml

3. The local.properties file is critical for these builds and will also vary according to build machine. So next step is to copy that file over:

xcopy /y/q "D:\Property_files\Android_trunk\local.properties" D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk

4. For Android builds it's critical that the version.code be incremented each build. The new build must have a higher value for version.code in the Android manifest, or loading the app should fail for the user. So the next step in the build is to copy over a build.number file that will then get incremented by an ANT task. This file follows standard ANT increment format (will go in detail in another post):

xcopy /y/q "D:\Property_files\Android_trunk\build.number" D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk

5. We always do an ant clean task before build:

setlocal
set JAVA_HOME=D:\ProgramFiles\Java\jdk1.6.0_11
set ANDROID_HOME=D:\ProgramFiles\Java\android-sdk-windows
set ANT_HOME=D:\ProgramFiles\Ant\apache-ant-1.7.1\apache-ant-1.7.1
cd D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk
ant clean

6. We then originally ran a gamut of replace tasks on the manifest file. Dev have revised the procedure so that the only extra task we need to do is update that version.code value:

setlocal
set JAVA_HOME=D:\ProgramFiles\Java\jdk1.6.0_11
set ANDROID_HOME=D:\ProgramFiles\Java\android-sdk-windows
set ANT_HOME=D:\ProgramFiles\Ant\apache-ant-1.7.1\apache-ant-1.7.1
cd D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk
ant updateversioncode

7. Then run release to create the Android build:

setlocal
set JAVA_HOME=D:\ProgramFiles\Java\jdk1.6.0_11
set JAVA_OPTS=-Xms64m -Xmx256m
set ANDROID_HOME=D:\ProgramFiles\Java\android-sdk-windows
set ANT_HOME=D:\ProgramFiles\Ant\apache-ant-1.7.1\apache-ant-1.7.1
set ANT_OPTS=-Xms64m -Xmx256m
cd D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk
ant release

8. We then sign the release. Since the build machines are 'locked down' we pass these values in through the build itself:

setlocal
set JAVA_HOME=D:\ProgramFiles\Java\jdk1.6.0_11
set ANDROID_HOME=D:\ProgramFiles\Java\android-sdk-windows
set ANT_HOME=D:\ProgramFiles\Ant\apache-ant-1.7.1\apache-ant-1.7.1
cd D:\ProgramFiles\Java\jdk1.6.0_11\jre\bin
jarsigner -keystore D:\ProgramFiles\Java\jdk1.6.0_11\bin\blah.keystore -storepass blah2 -keypass blah2 -signedjar D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk\bin\blah3pre.apk D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk\bin\blah3-unsigned.apk blah_key

9. We then need to do a zipalign on the output, this is required for Android deliveries:

setlocal
set JAVA_HOME=D:\ProgramFiles\Java\jdk1.6.0_11
set ANDROID_HOME=D:\ProgramFiles\Java\android-sdk-windows
set ANT_HOME=D:\ProgramFiles\Ant\apache-ant-1.7.1\apache-ant-1.7.1
cd D:\ProgramFiles\Java\android-sdk-windows\tools
zipalign -f -v 4 D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk\bin\blahpre.apk D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk\bin\blah.apk

10. Since we incremented the build.number file we need to move it back so that the next build increments again:

xcopy /y/q "D:\Hudsonb\jobs\Android-trunk\workspace\android_trunk\build.number" D:\Property_files\Android_trunk

Next post, diving into the details of the manifest replace steps and how Android uses the properties files

Thursday, May 27, 2010

Hudson iPhone builds part 3

I ran into some issues with delivering the completed iPhone zip from the Mac, so I ended up creating some separate deploy jobs that take care of it.

1. In the trunk builds I have the 'Build other projects' setting checked and call the deploy job. For branch builds I use the 'Trigger parameterized build on other projects' and choose 'Current build parameters', the reason being that I need to send the branch value to the deploy job.

2. I have the 'Post-build Actions' - 'Archive the artifacts' set for the build job. This takes the zip created by the Mac and archives it locally on the Hudson server. This is critical to the issue with Mac delivery.

3. For the configuration of the deploy job, I have the 'Advanced Project Options' - 'Use custom workspace' setting checked, and list the builds folder of the parent Hudson job that initiates this deploy job. It will find the zip that was archived to Hudson in the previous step. This means that each build needs its own deploy job, which doesn't scale perfectly, but since this is limited to Mac builds it's been working out OK

4. The next step in the deploy job is 'Publish artifacts to SCP Repository' and send it from the Hudson archive location.

5. There is then a job called to delete the zip from the Hudson server. This is because the archive job retains at a minimum two zips (last two successful), and we don't want the deploy job to deliver two. The delete job is called with 'Build other projects'

6. For the delete job the 'Use custom workspace' is using the build home from the original build job but handles the deletes for all jobs. This is one line that's called from the job:

del /s/q \hudson-iPhone*.zip

That's it for the build and delivery, maybe will dive into the iPhone code signing next