Skip to content

Instantly share code, notes, and snippets.

@Amimul100
Created August 25, 2014 04:47
Show Gist options
  • Save Amimul100/d79999069ad19a4d3043 to your computer and use it in GitHub Desktop.
Save Amimul100/d79999069ad19a4d3043 to your computer and use it in GitHub Desktop.
Titanium Android Module Developer Guide
Hello, Here is Guide to Build a Android Module in Titanium, And Creating the dist.zip file. For More Details Please follow this link below.
http://docs.appcelerator.com/titanium/latest/#!/guide/Android_Module_Development_Guide
Titanium Android Module Developer Guide
Requirements:
* Titanium Mobile SDK 1.5.0 or above
* A recent version of Python (>= 2.5) on your PATH or configured with PYTHONHOME.
- In Windows, Titanium Developer / Desktop ships with Python 2.5, so no extra configuration is needed.
* Sun JDK 6.0
- Android SDK, with both Google APIs and SDK version 4 installed You can target other versions of Android, but version 4 is a requirement for building
* Ant 1.7.1 or above in your PATH
- If you don't want to install Ant separately, you can optionally use Eclipse
Environment setup
The titanium script in the Mobile SDK is the frontend to creating and testing modules. It's recommended that you setup an alias or add it to your PATH so you can call it directly, for example:
In Windows: Open your environment variable settings by going to:
* Start Menu > Right click on "Computer" > Properties > Advanced System Settings
* Click on the "Advanced" tab, and the "Environment Variables" button near the bottom
* Double click or create a new entry for PATH under User Variables
* in Window Vista or Windows 7:
- Add C:\ProgramData\Titanium\mobilesdk\win32\1.5.0
* In Windows XP:
- Add C:\Documents and Settings\All Users\Application Data\Titanium\mobilesdk\win32\1.5.0
In OSX, Add this to your ~/.bash_profile <pre>alias titanium="/Library/Application\ Support/Titanium/mobilesdk/osx/1.5.0/titanium.py"</pre> or <pre>alias titanium="$HOME/Library/Application\ Support/Titanium/mobilesdk/osx/1.5.0/titanium.py"</pre> depending on where your mobile SDKs are installed.
In Linux, Add this to your ~/.bash_profile <pre>alias titanium=$HOME/.titanium/mobilesdk/linux/1.5.0/titanium.py</pre>
Testing the titanium script
Once you have the environment setup, you should be able to run titanium in a console window, and see the following output: <pre>$ titanium Appcelerator Titanium Copyright (c) 2010 by Appcelerator, Inc.
commands:
create - create a project run - run an existing project emulator - start the emulator (android) help - get help</pre>
Creating a module
To create a module, we need to pass some arguments to the titanium create command, namely:
* The module's name ($MODULE_NAME) and ID ($MODULE_ID)
* The platform we're creating a module for (android)
* The top-level path to your installation of the Android SDK ($ANDROID_SDK) (e.g. /opt/android-sdk)
For an Android module, we can create it with the following command from the parent directory of where you want the module created: <pre>titanium create --platform=android --type=module --name=$MODULE_NAME --id=$MODULE_ID --android=$ANDROID_SDK</pre>
As an example, we'll create a module that performs simple addition and subtraction, call it the "calc" module, and give it an ID of "org.appcelerator.calc". Here we use /path/to/android-sdk to point to the place where we extracted the Android SDK. <pre>titanium create --platform=android --type=module --name=calc --id=org.appcelerator.calc --android=/path/to/android-sdk</pre>
If this was successful, there should be a calc folder under the current directory.
Module project layout
Inside the module folder, you'll see a tree of files and directories that have been generated:
* LICENSE - The module's full license text
* build.properties - An Ant properties file that contains the location to the Titanium SDK and Android SDK
* build.xml - The main Ant build script - You will use this to build, distribute, and test your module
* manifest - The module's manifest that contains version, author, license, copyright, name, id, GUID, and platform information
* timodule.xml - A place to put custom activities, and general XML for insertion in AndroidManifest.xml (more doc coming soon)
* hooks - A directory with scripts that will be called when a module is added/installed/removed/uninstalled from a project (this is still a WIP)
* documentation - A generated Markdown file lives here that contains example documentation for your module
* assets - Module specific assets such as images live here (see the README)
* lib - Place any third party JAR dependencies here and they will be automatically added to your project's classpath and module zip
* src - The source code for your module(s)
* example - The module example project
Eclipse integration
Titanium also creates the necessary files so that you can import your module project directly into Eclipse. In Eclipse, simply follow these steps:
* In the top level menu, Click on File > Import...
* Expand the General folder, and double click on Existing Project into Workspace
* Click on Browse... next to the Select root directory text field
* Choose your module project's folder
* You should see your module project under the Projects list: Eclipse Module Project Import
* Press Finish and your module project should now be visible from the Package Explorer view in Eclipse
Building the module zip
The zip under the dist folder is the module's distributable form. It generally follows the naming pattern <pre>$MODULE_ID-android-$MODULE_VERSION.zip</pre>
The zip contains:
* The compiled JAR with classes, generated bindings, and resources from the module project (built from the src folder)
* Third party JARs found in the lib folder
* The module manifest, which includes deployment metadata such as author, version, license, copyright, etc
* The module's timodule.xml
Building from command line / Ant
If ant is already on your PATH, then simply execute it from the top level directory of your module.
On the first build, you should see output similar to this: <pre>$ ant Buildfile: /Users/marshall/Code/test/test_modules/calc/build.xml
init: [mkdir] Created dir: /Users/marshall/Code/test/test_modules/calc/build/classes [mkdir] Created dir: /Users/marshall/Code/test/test_modules/calc/dist
process.annotations: [javac] Compiling 2 source files to /Users/marshall/Code/test/test_modules/calc/build/classes [javac] Note: [KrollBindingGen] Running Kroll binding generator. [javac] Note: [KrollBindingGen] No binding data found, creating new data file. [javac] Note: [KrollBindingGen] Found binding for module Calc [javac] Note: [KrollBindingGen] Found binding for proxy Example
compile: [javac] Compiling 2 source files to /Users/marshall/Code/test/test_modules/calc/build/classes [copy] Copying 1 file to /Users/marshall/Code/test/test_modules/calc/build/classes
dist: [jar] Building jar: /Users/marshall/Code/test/test_modules/calc/dist/calc.jar [zip] Building zip: /Users/marshall/Code/test/test_modules/calc/dist/org.appcelerator.calc-android-0.1.zip
BUILD SUCCESSFUL Total time: 1 second</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment