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:
- Oracle JDK
- iOS SDK (8.0+, only on macOS systems)
- Android SDK (4.1+)
- Node.js (8.x LTS+)
The following additional software is required for building the Titanium SDK:
- Git
- Android NDK
- Visual C++ 2010 Express (for Windows)
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.
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.
Varible |
Value |
---|---|
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/appcelerator/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
.git/config
file. -
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/appcelerator/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/*
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/appcelerator/titanium_mobile/blob/master/README.md#building-locally on how to build locally with Node.JS scrips.
In the root of your titanium_mobile
repo, run the following commands:
npm install node scons.js 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.
node scons.js 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_dir/dist/mobilesdk-<version>-<os>.zip
, where
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,
such as windows
or 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 Using Studio
Note that if you install an SDK using Studio, it will appear in Studio with the default version number. If you want to rename your custom SDK, see To Install the SDK Manually.
- Click Help > Install Titanium SDK....
- Select Install from URL.
- Click Browse. Browse your
<titanium_mobile_dir>/dist
folder and select the zip file. - Click Finish.
To Install the SDK Manually
- Unzip the zip file.
- Inside the
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.2.0.TIMOB-1234
. - Copy the SDK folder to the folder where your other Titanium SDKs are installed.
The default installation folder for SDKs varies by operating system:
- macOS:
~/Library/Application Support/Titanium
- Windows:
%ProgramData%\Titanium
Speeding Up the Titanium SDK Build
The process of compiling the Titanium SDK source code 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%!
Use ccache
The Android NDK can use ccache, a tool for reusing cached C/C++ compilations. We get huge improvements in build time with it.
- Install HomeBrew if you don't have it installed already
- Install
ccache
with the following command:brew install ccache
- Set an environment variable
NDK_CCACHE
to point to it. Installed with HomeBrew, the command would be:export NDK_CCACHE=/usr/local/bin/ccache
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_CPUS
equal to the above value. In this case:export NUM_CPUS=4
3 コメント
Ashraf Abu Samah
Will need to update this doc to add in the new method to build the SDK locally. Currently, I only added a reference to the README.md of the github repo.
Brian Immel
Agreed. Can you create a TIDOC ticket with the README.md's location and other bits of info I would need to revise this page?
Farzad Merzadyan
Under
Parallelize Compiling
it's much faster to runsysctl hw.ncpu
to find number of cores. Output states number of threads the machine can run.