# Building the Titanium SDK From Source
This document provides information on how to build Titanium SDK from source files by listing software requirements, how to set up your environment, where to get the source files, building the SDK, how to install a build SDK, and speeding up the Titanium SDK build.
# Software Requirements
You must have the following software installed to be able to compile the Titanium SDK. (Click on any item to get instructions on how to install it for your system.)
The following software is required for building Titanium applications, and you probably already have it installed:
The following additional software is required for building the Titanium SDK:
Many of these items you may already have installed for developing Titanium applications.
To build the SDK for Android, you must have either Apache Ant or Eclipse and ADT installed. In most cases, you should probably have both--Ant for command-line builds, and Eclipse and ADT for interactive builds and debugging. Building the SDK using
scons, as described here, requires Ant.
ADT has been discontinued and we don't recommend using it.
# Windows Notes
For Windows, if you use Studio, you may need to reinstall some of the tools, such as Git, Java and Node.js, and modify your PATH variable to the new locations of the binary executables. Paths to tools should not contain spaces.
# Setting Up Your Environment
The following environment variables must be set in order to build the SDK from source.
|ANDROID_SDK||Android SDK directory, for example, |
|ANDROID_NDK||Android NDK directory, for example, |
|JAVA_HOME||Oracle JDK directory, for example, C:\Java\ jdk 1.8.0_121|
# Getting the Source
The simplest way to get the SDK source is to simply clone it:
git clone https://github.com/tidev/titanium_mobile.git
However, if you have any interest in contributing to Titanium, you should create your own fork of the
titanium_mobile repository on github, as described in the Pull Request Guide.
# Checking Out a Pull Request Locally
If you want to test a changes that is a pull request on Github, you can add and checkout remote PR branches to your local titanium_mobile repo. Note that there are over 10000 PRs in the titanium_mobile Github repo, and over 10000 remote PR branches will be linked to your local repo. They will not be downloaded until you explicitly clone them.
To add the remote PR branches:
From the root level of your titanium_mobile repo, open the
Locate the appcelerator/titanum_mobile repo contents in the file. Note that the remote repo name will be different depending on how you retrieved the appcelerator/titanum_mobile remote repo. In the example below, it was name "upstream".
[remote "upstream"] fetch = +refs/heads/*:refs/remotes/upstream/* url = https://github.com/tidev/titanium_mobile.git
Add the following line to the section and replace
<remote_name>with the name of the remote repo:
fetch = +refs/pull/*/head:refs/remotes/<remote_name>/pr/*
In the previous example, the section now looks like:
[remote "upstream"] fetch = +refs/heads/*:refs/remotes/upstream/* url = https://github.com/tidev/titanium_mobile.git fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
Fetch the remote PR branches:
git fetch upstream
Checkout the PR you want to test:
git checkout pr/####
To remove the PR remote branches, run the following command:
git fetch upstream --prune
# Build the SDK
The method written below is the old way. The repo has now been updated to do away with scons. Please refer to https://github.com/tidev/titanium_mobile/blob/master/README.md#building-locally (opens new window) on how to build locally with Node.JS scrips.
In the root of your
titanium_mobile repo, run the following commands:
npm install npm run cleanbuild
By default, the above will build the SDK for all platforms. You can specify platforms to limit the generation of unmentioned platforms, e.g.
npm run cleanbuild ios.
When updating to a new version of the SDK, it is usually necessary to rerun
npm install to update the local Node dependencies.
# Installing a Built SDK
Once you've built the SDK successfully, the built SDK is in
titanium_mobile is the root of your local repo,
<version> is the current version of the SDK master branch, and
<os> is the OS you built for,
osx. By using the above Node commands, the SDK will automatically installed for you. To manually install a packaged SDK,
select one of the following options:
# To Install the SDK Manually
Unzip the zip file.
mobilesdk/<os>folder, there is a folder named with the version number (for example, 7.2.0). You may want to rename this folder so you can distinguish it later – for example, 8
Copy the SDK folder to the folder where your other Titanium SDKs are installed.
The default installation folder for SDKs varies by operating system:
# Speeding Up the Titanium SDK Build
The process of compiling the Titanium SDK source code (opens new window) can be very time consuming if your environment is not primed to do so. Here's a short list of tips and tricks for getting that compile time down. In our testing so far, these tips can reduce compile time by as much as 80%!
At this time, the instructions refer specifically to speeding up the Titanium SDK build on a macOS machine.
# Use ccache
The Android NDK can use ccache (opens new window), a tool for reusing cached C/C++ compilations. We get huge improvements in build time with it.
Install HomeBrew (opens new window) if you don't have it installed already
ccachewith the following command:
brew install ccache
Set an environment variable
NDK_CCACHEto point to it. Installed with HomeBrew, the command would be:
# Parallelize Compiling
The NDK can also parallelize while compiling, which can speed up the process.
Determine how many cores your machine has. You can use this command on macOS:
system_profiler | grep -i "Number Of Cores"
Multiply the above number by 2. So if the above command returned
Number of Cores: 2, then your value should be 4.
Set an environment variable
NUM_CPUSequal to the above value. In this case: