The SmartBody code is cross-compiled for the Android platform using the native development kit (NDK), which allows you to use gcc-like tools to build Android applications. This means that SmartBody is nearly fully-functional as a mobile application, since it uses the same code base as the desktop version of SmartBody. Many of the supporting libraries (such as ActiveMQ, boost, Xerces, Python, Festival, etc.) have already been built as static libraries and exist in the smartbody/android/lib directory.
Note that there are three different examples of Android applications using SmartBody that can be built: sbjniapp (A simple app using the Java Native Interface), sbogreapp (an Ogre-based app), and vh-wrapper (a set of libraries that can be used in conjunction with the Unity game engine).
If your target hardware is the ARM architecture, some dependency libraries are already prebuilt at SmartBodyDir)/android/lib. Therefore you can build the SmartBody projects directly as below:
Build Instructions for Android | |
---|---|
1 | Download and install android-sdk from : http://developer.android.com/sdk/index.html |
2 | Download and install the android-ndk from: (Note that when building on the windows platform, you will also need to install cygwin 1.7 or higher from http://www.cygwin.com/ ) Follow the installation instruction for both the SDK and the NDK. Be sure to set the correct path to android-sdk/bin, android-ndk/bin so the toolchain can be access correctly. For NDK, you also need to export the environment variable NDK_ROOT to the NDK installation directory ( for example, export NDK_ROOT= "/path/to/ndk/directory" ) |
3 | Install Eclipse ( http://www.eclipse.org/ ) and its Android ADT plug-in ( http://developer.android.com/sdk/eclipse-adt.html ) The supporting libraries have been built using Android version 2.3.3 or higher. |
4 | (Optional) Build sbjniapp sbjniapp is a hello world project for SmartBody. It has very basic rendering and minimal functionality, but it helps demonstrate the SmartBody port on android. i) Go to (SmartBodyDir)/android/sbjniappi/ ii) ndk-build ( Similar to gcc, you can set the option -j $number_threads to accelerate the build process with multi-threading). iii) copy the directory (SmartBodyDir)/android/sbm-jni/sbjniappdata and its files to sdcard directory of your android device. ( Usually under /sdcard/ ) iv) Use Eclipse to open the project (SmartBodyDir)/android/sbjniapp/. v) Select Project->Build Project. Connect the device and then run the program as "Android Application". |
5 | (Optional) Build sbogreapp sbogreapp combines SmartBody and Ogre for high quality rendering. Currently, it is very slow when rendering in deformable model mode.
|
6 | (Optional) Build vh-wrapper vh-wrapper is a SmartBody interface to Unity3D. Note that SmartBody connects to Unity via Unity's native code plugin interface, which presently requires a Unity Pro license. In addition, the Unity project needs to be compiled for Android, so a Unity Android license is needed as well.
|
Build Environment
I was using Ubuntu 14.04 as the host system. The NDK version used for building these libraries is r9d. For now, you should avoid using NDK version >= r10 since Google removed some API calls such as __srget, __swbuf, and etc. This would cause problems when trying to compile some libraries.
Once you install both the Android SDK and NDK, you also want to add these the environment variables in ~/.bashrc :
export PATH=${PATH}: /path/to/android/android-ndk-r9d
export ANDROIDSDK= /path/to/android/android-sdk-linux/
export ANDROIDNDK= /path/to/android/android-ndk-r9d/
export AndroidNDKRoot= /path/to/android/android-ndk-r9d/
export ANDROIDNDKVER=r9d
export ANDROIDAPI=18
Note that it is important to set ANDROIDAPI=18, since Google (again!) introduced some problem in Android API>=19 that will cause linking error for Python C library.
You would also want to install git so that you can quickly checkout the build scripts for both Python and Boost online. To do so, open the terminal and type "sudo apt-get install git" to install git.
Building Python
We will use the build scripts from https://github.com/kivy/python-for-android to build the Python library from source :
- Run "git clone git://github.com/kivy/python-for-android" in terminal to checkout the latest version.
- Under directory "python-for-android", run ./distribute.sh -m "pil". The script will automatically download and build the Python 2.7 library. This process will take several minutes and will be utilizing both the Linux gcc tool-chain, as well as the Android NDK tool-chain you provided in the environment variables.
- You can then find "libpython2.7.a" at "/python-for-android/build/python/Python-2.7.2".
- You would also find include files at "/python-for-android/build/python-install/include/python2.7". Later when you are building SmartBody, it should point to these include files for Python.
- You also want to create a folder "/sdcard/Python27/Lib" on your Android device, and put the Python library files in this folder. The Python library files can be found at "/home/fengww/SmartBodyDev/py4a/python-for-android/build/python-install/lib/python2.7".
Building Boost 1.59 ( Including Boost.Python )
We will use the build scripts from https://github.com/MysticTreeGames/Boost-for-Android to build the boost library. However, the script by default only supports up to Boost 1.55 and it does not setup to build Boost Python. Therefore we need to customize the build script and corresponding configurations to build the latest Boost 1.59 that includes Boost.Python.
- Run "git clone https://github.com/MysticTreeGames/Boost-for-Android.git"
- Copy over the custom config and script files from "$(SmartBodyDIR)/android/boost/Boost4A/" to "Boost-for-Android" directory ( the directory contains the build scripts we just checked out ).
Run "./build-android-SB.sh /path/to/android/ndk". This script will automatically download Boost 1.59 and build necessary libraries ( For SmartBody, it requires filesystem, system, regex, and python ).
- You can then find the binaries for the library at "/Boost-for-Android/build/lib" folder. The header files can also be found at "/Boost-for-Android/build/include/boost-1_59/".