Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
282 lines (206 sloc) 11.5 KB

Getting started with Appcelerator Titanium (OSS Version) and Atom

Since version 4 of Appcelerator Titanium there are two version of Titanium: the 'Appcelerator Platform' (with Appcelerator Studio, Arrow,..) and the open source version 'Appcelerator Titanium' (http://appcelerator.org/). In this tutorial I'm talking about a way to get started with the open source Titanium in combination with Atom as an editor on Linux (you could use other editors like Sublime, but that's not part of this tutorial).

main view

Table of Contents generated with DocToc

Installing Appcelerator Titanium

The current (at the moment of doing this doc) free 'general availability' version of the SDK was 4.1.0.GA

At first we need to setup Titanium:

  • command line tools (CLI) to compile the apps
  • the MVC framework Alloy
  • some useful tools
  • the SDK

The main parts are installed using the node.js package manager 'npm'. Check https://nodejs.org/ if you need to install it.

Linux (Fedora)

If you are using Fedora 23/24 you can run the following commands to get the needed libraries:

# install tools and libraries needed for android sdk
dnf install nodejs npm git gcc glibc.i686 glibc-devel.i686 libstdc++.i686 zlib-devel.i686 ncurses-devel.i686 libX11-devel.i686 libXrender.i686 libXrandr.i686

# intall npm version 4.2.2
npm install -g npm
npm install n -g
n 4.2.2

# install cli tools
npm install -g titanium alloy appcelerator tisdk
echo " PATH=$PATH:$HOME/.local/bin:$HOME/android-sdk-linux/tools:$HOME/android-sdk-linux/platform-tools:/usr/java/latest/bin"
echo " export ANDROID_SDK=$HOME/android-sdk-linux"
echo " export JAVA_HOME=/usr/java/latest"
echo "export PATH"

OSX / Windows

TODO: install node/npm on Windows / OSX

Open a console and run the following command to install the tools:

npm install -g titanium alloy tisdk

Titanium SDK

After that we need to install the SDK. To do this we will the cli tool tisdk from David Bankier (https://github.com/dbankier/tisdk):

# list available titanium sdks
tisdk list

The output will be something like this

4.1.0.GA
4.1.0.Beta
4.0.0.RC5
4.0.0.RC4
4.0.0.RC3
4.0.0.RC2
4.0.0.RC
4.0.0.GA
...

From this list we select the latest GA (4.1.0) and istall it

tisdk install 4.1.0.GA

with this command you can check if titanium found the sdk:

ti sdk list

and with

ti info

you can see if something is missing (How to install JDK and the Android SDK will follow)

You are ready to create titanium/alloy projects now and compile them! Time to setup the editor

get the newest SDK

The newest SDK is not available as a binary with tisdk. You have to compile it with:

tisdk build 5.0.0.GA

For more information visit https://github.com/dbankier/tisdk and have a look at "Manual builds"

other methods

Install Atom (and some useful packages)

Goto https://atom.io/ and install the atom editor.

Then install some Atom packages for easier Titanium coding:

Name Type Features
titanium language javascript Language JS Autocomplete (non alloy)
Titanium Alloy add-on All-in-one package
Jump to definition
Open related
TSS Highlight
Ti-Create add-on Create projects, controller, modules
Titanium-Build add-on Run in simulator (wip)

Other useful non-titanium packages/add-ons:

Name Features
Atom Beautify Code beautifier (tss, xml, js support)
DocBlockr A helper package for writing documentation
highlight-selected Highlights the current word selected when double clicking
Linter-jshint Linter plugin for JavaScript (this checks your JS code)
Linter A Base Linter core with Cow Powers (does nothing by itself, it's an API base)
minimap-highlight-selected A minimap binding for the highlight-selected package
minimap A preview of the full source code.
pigments A package to display colors in project and files.
Platformio-ide-terminal An active fork from previous terminal package for Atom, running in newer versions, complete with themes and more
Project Manager Project manager
symbols-list Will display all functions in a sidebar
sync-settings Syncs Atom settings, plugins etc using Gists. Very handy if you have multiple machines and want to have the same settings everywhere
Terminal-plus A terminal package for Atom, complete with themes and more. NOTE: will probably fail with newer Atom versions, try next

Create your first app

For this tutorial we are just creating an empty Alloy app using CLI and Atom.

Open a new terminal and add the following :

ti create --id com.test -d . -n APPNAME -p all -t app -u http://migaweb.de
cd APPNAME/
alloy new

This will create a basic app (name: APPNAME, bundle identifier: com.test, type:app, platform: all) and the convert it into an Alloy project.

You can also use the Atom package ti-create

main view

It will create a new project inside the folder that is open in the tree-view. 'Create controller/widget' only work inside an existing Alloy project ("Open folder" - select the project folder).

Compile your app

There are several ways to compile your app. You can use the simulator/emulator, deploy it to your device or create store apk's/ipa's. There is also a live test tool (TiShadow) which saves you a lot of time waiting for the compiler.

cli way

# android to device
ti build -p android  -T device

# android to store/file
ti build -p android -K /home/user/keyfile.keystore -T dist-playstore

# iOS simulator: will show a menu to select the size/device (e.g. press 8 for iPhone 5S
ti build -p ios -C ?

# iOS ipa/device/store: will show you a menu to select the different profiles
ti build -p ios --target ?
iOS related

To list all distribution names you can use:

security find-identity -v -p codesigning

Shortcuts

You can save yourself a lot of typing when you define some aliases (e.g. 'tq' will run the whole ti command to compile it and deploy it to the connected android device).

Linux / OSX

In Linux/OSX you open the .bashrc file and add the following aliases:

alias tq='ti build -p android  -T device --skip-js-minify'
alias tq_ios='ti build -p ios --deploy-type production --distribution-name "DIST_NAME" --ios-version 8.4 --keychain  --pp-uuid PROF_ID --target dist-adhoc --output-dir .'
alias tbs='ti build -p android -K /home/user/keyfile.keystore -T dist-playstore'
alias tq_select='ti build -p ios -C ?'

then you can just write "tq" to compile and install on your connected device or write "tbs" to build an apk for the play store.

Windows

In Windows, the basic aliases command is not enough (you can't attach options in alias), so you must use .bat files or, a better solution, powershell aliases+functions. As you may want to have it permanently on your shell session, first you must create a powershell session file, the equivalent to .bashrc on Linux. So, open a PowerShell command line and do:

NOTE: You should need to activate the execution policy allowing scripts locally in order this solution to work. Open the powershell command line as administrator and type set-executionpolicy remotesigned

# Checking if profile exists
PS C:\> $profile
# If you cannot see/access the indicated folder, force the creation
PS C:\> New-Item -path $profile -type file -force

Ok, now you can open the Microsoft.PowerShell_profile.ps1 file and create your functions+aliases

Function appcBuildAndroid {ti build -p android -T device --skip-js-minify}
New-Alias tib appcBuildAndroid

Function appcBuildPlayStore {ti build -p android -K C:\Android\Mykeys\keyfile.keystore -T dist-playstore}
New-Alias tibs appcBuildPlayStore

The next time you open a PowerShell console, you will have available the aliases tib and tibs to compile for Android or for Play Store. Of course they are examples. Do as many as you want.

Here you can see a Windows Power Shell profile example, preconfigured: https://gist.github.com/mcvendrell/b4bacd36b834303a4e5f61afc947706a

TiShadow

TiShadow is another great tool by David Bankier (https://github.com/dbankier/TiShadow)

TiShadow provides Titanium developers the ability to deploy apps, run tests or execute code snippets live across all running iOS and Android devices.

It allows you to quickly test your app on multiple devices at the same time and 'compiles' quicker then building your app all the time (about 5 seconds to get your app up and running on an android phone, for a small app). Also it works over wifi, so you don't have to have your device connected.

Link list

Here are some useful Titanium ressources:

Contact me

Feedback appreciated.