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 readinghttp://www.openscenegraph.org/projects/osg/wiki/Support/PlatformSpecifics/Androidandhttp://developer.android.com/sdk/ndk/index.htmlScreenshots are available here:http://imgur.com/a/VEyrgInitial 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$HOMEalways
stands for/home/USERwhereUSERdenotes
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)g++Download Eclipse and extract it. I'm using$HOME/Android/eclipse/My version is Eclipse Indigo.Download the Android SDK (my version: r16) and extract it into$HOME/Android/android-sdk-linux/Install the ADT-Plugin into eclipse. This works like this: start eclipse and on the top panel go toHelp
→ Install New Software. In the Field labeled „Work with:“ fill in:https://dl-ssl.google.com/android/eclipse/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 toWindow
→ 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$HOME/Android/android-sdks/to have it all in one place.Extract the Android NDK to$HOME/Android/android-ndk-r7b/Developers with an already working environment should be able to start here.Installing OpenSceneGraph 3.0.1 for Android with OpenGL ES 1.xDownload OpenSceneGraph-3.0.1 and extract it to$HOME/Android/OpenSceneGraph-3.0.1/Download the 3rd Party Dependencies and extract it to$HOME/Android/OpenSceneGraph-3.0.1/3rdparty/Set the environment variable ANDROID_NDK so that the cmake building script can find it. Go to/home/USER/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):export ANDROID_NDK=$HOME/Android/android-ndk-r7b
export ANDROID_SDK=$HOME/Android/android-sdks(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):mkdir $HOME/Android/OpenSceneGraph-3.0.1/build
mkdir $HOME/Android/OpenSceneGraph-3.0.1/osginstall
cd $HOME/Android/OpenSceneGraph-3.0.1/buildThis created a directorybuildin
the OpenSceneGraph-directory. This is where we will place our build in. Theosginstalldirectory
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/osginstallAfter that we can build it:make...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/osginstallinto
the foldersobj,lib,
andinclude:make installAfter this is finished, we are ready to start the eclipse project. Before starting eclipse, copy the folder osgAndroidExampleGLES1 from$HOME/Android/OpenSceneGraph-3.0.1/examplesto$HOME/workspace/osgAndroidExampleGLES1(or wherever else your eclipse workspace is).Copy the three foldersobj,lib,
andincludefrom
inside the$HOME/Android/OpenSceneGraph-3.0.1/osginstallfolder
into$HOME/workspace/osgAndroidExampleGLES1(replace
if necessary).Start eclipse and go toNew
→ Projectand choose “Android Project“. Next, then choose „Create project from existing source“ and set the location to/home/USER/workspace/osgAndroidExampleGLES1The Project Name should be osgAndroidExampleGLES1. (SCREENSHOT6)Next, the build target should be Android 2.2 or higher.Expand the project and open the folderjni.
Open the fileAndroid.mkChange line 7 to:OSG_ANDROID_DIR := /home/USER/workspace/osgAndroidExampleGLES1Change line 21 to:LOCAL_DLIBS := -llog -lGLESv1_CM -ldl -lz -lgnustl_staticand save it. (SCREENSHOT7)In a Terminal window, go to the project directorycd $HOME/workspace/osgAndroidExampleGLES1We need to update the build.xml. Type$ANDROID_SDK/tools/android list targetsand 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 . -swhere you have to exchange the „1“ with your id number. After that, build the project by executing$ANDROID_NDK/ndk-buildNow that we built the native part of the Android OSG Viewer, go back to eclipse and run it. That's it.Using OpenGLES2When 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/osginstallAs 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.