Appcelerator Blog

The Leading Resource for All Things Mobile

Get to know the Titanium CLI

0 Flares 0 Flares ×

As you may already known, Titanium SDK 3.2 is around the corner and amongst its many new features and enhancements, the CLI (command-line interface) has gotten more useful and powerful, as you can see in this recent slide deck by Chris Barber. When you use the Titanium CLI YOU are in control and you can use any text editor you’d like; in fact Titanium Studio uses the CLI for its own compilation and build operations.

In preparation for this new release, in this blog post we’ll explore how to get started with the CLI and start taking advantage of its flexibility.

Install the CLI

If you already have Titanium installed and working, then you already have Node.js and the CLI installed so you can skip to “Create a Project”. If you’re performing a fresh Titanium installation, you could use your text editor of choice together with the CLI.

  1. Assuming you’re starting from scratch, make sure you have Xcode (Mac-only) and the Android SDK Manager installed. Remember that you’ll have to open up the Android SDK Manager to download the actual SDKs you’d like to use for testing.

  2. Download and install Node.js.

  3. Open a Terminal/Command Window and follow these steps.

Install Titanium

 $ [sudo] npm install titanium –g

Login

 $ titanium login

Install Titanium SDK and set it as default

 $ titanium sdk update --branch 3_1_X –default

Configure Titanium

 $ titanium setup

Note: Make sure you provide the correct path to the Android SDK

Configure additional settings

 $ titanium setup --advanced

Note: The command ti is a shortcut to titanium and I’ll be using it from here on end.

Create a project

The CLI will allow you to send flags/arguments as a single instruction. All these flags are documented in the official documentation. Knowing them all, or at least the most important ones, is the key to unlocking the flexibility of the CLI because then you can use it for scripting and automation.

In the case of creating a new project, the CLI offers you a friendly way of providing flags using screen prompts.

 $ ti create

By running ti create you’re invoking a wizard of sorts that will ask you for details about this new project. When finished, your new project will be created. One very useful flag is -d, which overrides the default project directory you specified during the setup process. If for example your default folder is /tiprojects, you could write something like

 $ ti create -d /tiproject/newworkspace

to create this particular project in a different directory.

Build

Since iOS has only 1 simulator, building a project for iOS is pretty straight-forward.

 $ ti build -p ios

Building for Android requires additional flags to specify the emulator to use, its skin (screen size) and architecture (arm, x86, etc). To know which emulator to use you’ll need to run a command provided by the android sdk

 $ android list targets

This command will provide you a list and details of all the virtual devices you have installed. You don’t have to run this command every time, but only when you need to find the id of the emulator you wish to use. Notice that each of them has a sequential id. Take note of the one you wish to use, for example 11. To build for android using the WVGA854 skin and using an x86 emulator you’ll call:

 $ ti build -p android -I 11 -S WVGA854 -B x86

This command will build your app, invoke the specified Android emulator if it is not already running, install and run your app.

If you’d like to build to a Android device, simply run

 $ ti build -p android -T device

or for iOS

 $ ti build -p iOS -T device

Note: Building for iOS devices requires you to specify the certificate and provisioning profile to use, and currently the app will be deployed to iTunes. The 3.2 CLI will include the feature of bypassing iTunes and build straight to the iOS device.

Clean

To clean your project, go to your project folder and run
 $ ti clean

These are the basics of the CLI. Make sure you check the official documentation for details about all the available commands. At any moment you could use the –help flag to get more information about the command you’re running. For example: $ ti build –help will give you a description of all the possible flags for the build command.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

1 Comment

  1. Martin Johansson

    Thanks for the great article, I keep struggling with using the cli for publishing android to the play-store. Can you please show how you would do that for a project?

Comments are closed.

Sign up for updates!

Become a mobile leader. Take the first step to scale mobile innovation throughout your enterprise.
Get in touch
computer and tablet showing Appcelerator software
Start free, grow from there.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×