How To Create A Titanium Mobile Project From The Command Line

Titanium is a mobile platform, developed by Appcelerator, that allows developers to create cross-platform applications in Javascript. In earlier versions you were required to develop your apps using their custom IDE (gross). Fortunately, it's now possible to develop with their CLI tools and your own editor. I'll be covering how to do that in this post.

Note that the steps outlined here are for OSX. It'll be 99% the same on Linux. If you're on Windows, you may need to do a bit of Googling. Also note that you will NOT be able to develop for iOS on Linux or Windows.

If developing on OSX, you'll need the latest Xcode installed before continuing. Make sure to update it before continuing.
Getting The SDK


Although you can download their SDK manually via GitHub, I'd recommend installing their full package from the Appcelerator website. This will install their Studio IDE, which we'll use to manage the SDK versions and updates.

Once installed, open Titanium Studio (the IDE) and select: "Help" > "Check For Titanium SDK Updates" from the menu. Install the latest SDK if you don't already have it.

Now select "Titanium Studio" > "Preferences" from the top menu and expand Titanium Studio on the left. In the sub-menu select Titanium. The panel on the right will have a field named Titanium SDK Home, this is the full installation path. Copy that full path and move to the next step.

On OSX, open (or create if it doesn't exist) your ~/.bash_profile file and add the following:

alias titanium="/mobilesdk/osx//titanium.py"
alias ios_builder="/mobilesdk/osx//iphone/builder.py"

Replace with the full path you copied from the IDE settings and replace with the SDK version you'd like to use. Its easiest to browse the installation directory to see which versions are available and what the directory names are.

To add the new aliases to your environment, either completely close your terminal (if you have one open) or run:

source ~/.bash_profile

Now try running:

titanium

The output should look something like this:

Appcelerator Titanium
Copyright (c) 2010-2012 by Appcelerator, Inc.

commands:

  create - create a project
  run - run an existing project
  clean - clean builds
  emulator - start the emulator (android)
  docgen - generate html docs for a module (android)
  fastdev - management for the Android fasted server
  help - get help

If you see something like the above, you're ready to move to the next step. Otherwise, go through the steps above and check your work to ensure you didn't miss anything.
Creating A Project


Now for the fun part, creating a project. Open up your terminal and cd into the location where you'd like to create your project. Now run the following command:

titanium create --platform=iphone --name= --id=

Replace with your projects name, and with the a custom ID using reverse domain format. Here's a "Hello World" example:

titanium create --platform=iphone --name=HelloWorld --id=com.mydomain.helloworld

This will create the project folder HelloWorld/ in the current directory. If you need help or would like to see more options available when creating a project, run:

titanium help create

Next, we'll look at running your new project.
Running Your Project In An Emulator


To run your project, open terminal and cd into your project directory (where the tiapp.xml) file is located. Now run:

titanium run --platform=iphone

You'll see a ton of output during the build process. After some time, the iPhone emulator will open with your project running.

Thats all there is to it! Now you can head over to the Titanium Developer Docs and start building a Titanium app in your own editor! Hooray!


comments powered by Disqus