Titanium Mobile Development with Sublime Text 2 and IntelliJ IDEA

Dave Townsend
unbounded.io
Published in
4 min readOct 11, 2016

--

Original post date July 30th, 2012

Just spent the last week at Appcelerator building mobile web apps in beautiful Mountain View, CA for two 2-day certification training courses. They have a sweet product. But I’m not a fan of their IDE Titanium Studio, which is built on Eclipse and Aptana (who they recently acquired). It was really slowing me down when working through the labs. I’m a Sublime Text 2 (ST2) and Intellij IDEA user so I was in serious need of a more responsive tool and agile work flow. But, I did not want to lose code completion, nor the ability to build/deploy from my tool of choice. So I spent some time and got things working how I wanted. Here’s the steps I took to set up ST2 and Intellij IDEA for Titanium mobile development.

Titanium code completion for Sublime Text 2

The first thing you need to do is use jsca2js to get a JSDoc annotated file of Appcelerator’s JavaScript API. It’s super easy, just run the script and it will generate the file for you. Once you have that you will need to install the SublimeCodeIntel package and configure it for Titanium. (If your not familiar with ST2 packages read section 7 and 8 of this Nettuts post before continuing)

As you will see in the “Configuring” section of the SublimeCodeIntel GitHub page, you just need to create a “config” file in either your home dir or the project root dir.

Paste this into your config file and add the path to the directory on your machine that contains the “titanium-mobile-<version>.js” file.

{  "JavaScript": {     "javascriptExtraPaths":["add your path here"]  }}

Restart ST2 and you should now have code completion for Titanium.

Building Titanium Projects in Sublime Text 2 with MakeTi

There is great open source tool called MakeTi that lets you build your Titanium projects from the command line and has several integration features including a package for Sublime Text 2. The MakeTi GitHub page will help you get it installed.

One of the things I discovered when building with MakeTi is that out of the box, your app will build, but it will not be deployed in the simulator unless you have the iOS 5.0 Simulator SDK installed. I had 5.1 installed and it was not working right. If you then install 5.0 it will always default to the 5.0 simulator. You can get around this by tweaking the MakeTi.py file located in ~/Library/Application Support/Sublime Text 2/Packages/MakeTi/ to specify the SDK version of the simulator that you want to use.

Just add this between the existing if: and else: statements…

elif (self.instance_list[index] == 'iphone'):	
s = sublime.load_settings("MakeTi.sublime-settings")
self.window.run_command("exec",{"cmd":
["make","-C",root,"run","iphone=5.1","platform="+self.instance_list[index],"android_sdk_path="+s.get('androidsdk')]})

Now all you need to do is change the “iphone=5.1” parameter to whatever version of the simulator you want launched from the build. This lets you quickly deploy to different versions of the platform for iOS (assuming you have them installed). Haven’t tried this with Android yet because for me it’s a faster workflow to deploy directly to the device for Android and use the simulator for iOS.

Once MakeTi is all set up, you can quickly hit cmd+b on Mac and you will get a nice pop-up dialog to choose the platform in which to build and deploy your app.

Choosing iphone for instance will build/install your app and launch it in the iPhone simulator without ever having to leave the editor. Makes for a very agile workflow.

Titanium code completion for Intellij IDEA

To get code completion working for Intellij check out this blog post by Navin Peiris, he does a great job of detailing what you need to do. I got this working in Intellij and it works great. I did not see an obvious way to build the app in a cool way from the IDE, but you should be able to by finding a way to simply run the Makefile from inside the project. You may have to set up special run configs for each platform for instance.

Conclusions

Using ST2 for Titanium development is really nice, and I enjoy writing JavaScript with it. It’s super fast and has a ton of nice workflow features. The more I use it, the more cool things I find out about it. Intellij was cool too, but it was doing a lot if inspections that I had to turn off to get it to stop telling me things were errors when they weren’t. So it did not leave me with any real advantage over ST2 when using Titanium. For my Java and Groovy development there is no comparison, Intellij can’t be be beat in that space. It’s all about the sharpest tool for the job at hand. For Titanium development that tool, for me, is Sublime Text 2.

--

--