Compiling titanium mobile SDK from scratch

I recently needed to compile Titanium Mobile SDK from scratch. I was a little intimidated by the process. And as I feared, I ran into some nasty issues.

My build environment is a MacBook Pro running OS X 10.9.5. I’ve been using Titanium Studio on this machine for a while, building Titanium apps and even doing a little native module development with it.

I installed all the prerequisites as documented here. But I still ran into this nasty error:

My .bashrc file looked like this:

Despite the fact that my JAVA_HOME environment variable resolved to this:

for some reason, some part of the build process was trying to tack on an extra “/jre” to the end of my JAVA_HOME. I scoured the Interwebs for a cause and a solution. I found some articles that got close to the problem, but didn’t quite capture my problem, were Windows-specific, or the author didn’t fully explain the workaround.

I’m still a bit murky on why this happens, but somewhere inside of ant, it is using a different mechanism to define its java.home variable. It doesn’t get it directly from the JAVA_HOME environment variable. A lot of online posts refer to ways to change that within Eclipse. But I’m using the command line, so I didn’t think those approaches would apply in my case. It certainly doesn’t help that the error message implies that ant is using the JAVA_HOME environment variable.

My fix was to edit titanium_mobile/android/build/common.xml. For every <javac> element in the XML file, I added these properties:

So for example:

This got me past the “Unable to find a javac compiler” error. Woohoo! Now I’m on easy street, right? Wrong. Turns out that the Titanium Mobile SDK won’t compile with JDK 1.8 yet. You’ll get an error like this:

Turns out there’s even a JIRA issue for this problem.

OK, so I downloaded and installed JDK 1.7, made some adjustments to my .bashrc and to common.xml. My .bashrc became this:

My common.xml <javac> directives looked like this:

Much to my amazement and delight, the SDK compiled completely. There was a little weirdness at the end of the output:

but the ZIP archive with the SDK was created, and other than the last line, the output indicated success. BTW — on this machine, it took about 2 minutes to compile the whole thing, which I thought was surprisingly fast.

4 thoughts on “Compiling titanium mobile SDK from scratch

  1. You are a lifesaver!

    I had the exact same issues and couldn’t figure out what was going on until I read this post.

Leave a Reply

Your email address will not be published. Required fields are marked *