I decided to write a very easy step-for-step tutorial on how to build OSG for Android. I'm going to share it here. Corrections are of course welcome.
This Tutorial is to show how to compile OpenSceneGraph for Android and how to build the Example Application osgViewer on Ubuntu 11.10. It is meant as additional help and does not exempt the developer from reading
Screenshots are available here: http://imgur.com/a/VEyrg
Initial requirements are an already working Android Development Environment. I am using Eclipse Indigo, Android SDK r16, Android NDK r7b. Further required are cmake and g++.
In this tutorial $HOME
always stands for /home/USER
denotes the username.
Install Synaptic using the Software Center (SCREENSHOT1).
Install the package openjdk-6-jdk using Synaptic (SCREENSHOT2).
Install the following packages using Synaptic or apt-get.
cmake (sudo apt-get install cmake
Download Eclipse and extract it. I'm using
My version is Eclipse Indigo.
Download the Android SDK (my version: r16) and extract it into
Install the ADT-Plugin into eclipse. This works like this: start eclipse and on the top panel go to Help → Install New Software
. In the Field labeled „Work with:“ fill in:
and press Enter (SCREENSHOT3). After it has loaded the sources („Developer Tools“ is visible) (screenshot), check the „Developer Tools“ and click Next until everything is installed.
After restarting eclipse go to Window → Android SDK Manager
. Install AT LEAST Android 2.2 (API 8). This is the minimum required version for OSG on Android. (SCREENSHOT4). I installed it to
to have it all in one place.
Extract the Android NDK to
Developers with an already working environment should be able to start here.
Installing OpenSceneGraph 3.0.1 for Android with OpenGL ES 1.x
Download OpenSceneGraph-3.0.1 and extract it to
Download the 3rd Party Dependencies and extract it to
Set the environment variable ANDROID_NDK so that the cmake building script can find it. Go to
and open the file .bashrc
. You might need to make it visible. Do this with CTRL+H.
Edit the file (add the following lines to the end):
(alternatively you can use /home/USER/
instead of $HOME/
) (SCREENSHOT5). I added a variable for the SDK too, so that we don't always have to type the full path when accessing the SDK folder from the command line. Save it.
Open a Terminal. Type the following commands (replace USER with your username):
This created a directory build
in the OpenSceneGraph-directory. This is where we will place our build in. The osginstall
directory is where the make install command will later install our libraries and header files in. The next command will create the necessary makefiles. Change the last parameter according to the number of cpu-cores you have. I set it to 4, because I have a quadcore.
cmake .. -DOSG_BUILD_PLATFORM_ANDROID=ON -DDYNAMIC_OPENTHREADS=OFF -DDYNAMIC_OPENSCENEGRAPH=OFF -DOSG_GL_DISPLAYLISTS_AVAILABLE=OFF -DOSG_GL_MATRICES_AVAILABLE=ON -DOSG_GL_VERTEX_FUNCS_AVAILABLE=ON -DOSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE=ON -DOSG_GL_FIXED_FUNCTION_AVAILABLE=ON -DOSG_CPP_EXCEPTIONS_AVAILABLE=OFF -DOSG_GL1_AVAILABLE=OFF -DOSG_GL2_AVAILABLE=OFF -DOSG_GL3_AVAILABLE=OFF -DOSG_GLES1_AVAILABLE=ON -DOSG_GLES2_AVAILABLE=OFF -DJ=4 -DCMAKE_INSTALL_PREFIX=$HOME/Android/OpenSceneGraph-3.0.1/osginstall
After that we can build it:
...This will take a while, so go and grab a snack.
The following command will then install the libraries and headers into $HOME/Android/OpenSceneGraph-3.0.1/osginstall
into the folders obj
, and include
After this is finished, we are ready to start the eclipse project. Before starting eclipse, copy the folder osgAndroidExampleGLES1 from
(or wherever else your eclipse workspace is).
Copy the three folders obj
, and include
from inside the $HOME/Android/OpenSceneGraph-3.0.1/osginstall
folder into $HOME/workspace/osgAndroidExampleGLES1
(replace if necessary).
Start eclipse and go to New → Project
and choose “Android Project“. Next, then choose „Create project from existing source“ and set the location to
The Project Name should be osgAndroidExampleGLES1. (SCREENSHOT6)
Next, the build target should be Android 2.2 or higher.
Expand the project and open the folder jni
. Open the file Android.mk
Change line 7 to:
OSG_ANDROID_DIR := /home/USER/workspace/osgAndroidExampleGLES1
Change line 21 to:
LOCAL_DLIBS := -llog -lGLESv1_CM -ldl -lz -lgnustl_static
and save it. (SCREENSHOT7)
In a Terminal window, go to the project directory
We need to update the build.xml. Type
$ANDROID_SDK/tools/android list targets
and look for „android-8“ (Name: Android 2.2) in the output. Remember the id. My id is 1. The next command to execute in the terminal is:
$ANDROID_SDK/tools/android update project -t 1 -p . -s
where you have to exchange the „1“ with your id number. After that, build the project by executing
Now that we built the native part of the Android OSG Viewer, go back to eclipse and run it. That's it.
When compiling for OpenGLES2, the only difference is the „cmake“ command (and of course the osgAndroidExampleGLES2 example).
The corresponding cmake command for OpenGLES2 is as follows:
cmake .. -DOSG_BUILD_PLATFORM_ANDROID=ON -DDYNAMIC_OPENTHREADS=OFF -DDYNAMIC_OPENSCENEGRAPH=OFF -DOSG_GL_DISPLAYLISTS_AVAILABLE=OFF -DOSG_GL_MATRICES_AVAILABLE=OFF -DOSG_GL_VERTEX_FUNCS_AVAILABLE=OFF -DOSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE=OFF -DOSG_GL_FIXED_FUNCTION_AVAILABLE=OFF -DOSG_CPP_EXCEPTIONS_AVAILABLE=OFF -DOSG_GL1_AVAILABLE=OFF -DOSG_GL2_AVAILABLE=OFF -DOSG_GL3_AVAILABLE=OFF -DOSG_GLES1_AVAILABLE=OFF -DOSG_GLES2_AVAILABLE=ON -DJ=4 -DCMAKE_INSTALL_PREFIX=$HOME/Android/OpenSceneGraph-3.0.1/osginstall
As additional information to get the code completion to work for the c++ part of the project i followed this tutorial: http://permadi.com/blog/2011/09/creating-your-first-android-jnindk-project-in-eclipse-with-sequoyah/
Maybe if I have time I will add on to this tutorial how to debug it.
I do not take credit for inventing anything, I just compiled all the information I gathered into this document. Author: bernd.kampl(AT)gmail.com