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 http://www.openscenegraph.org/projects/osg/wiki/Support/PlatformSpecifics/Android and http://developer.android.com/sdk/ndk/index.html 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++. 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/USER/Android/eclipse/ My version is Eclipse Indigo. Download the Android SDK (my version: r16) and extract it into /home/USER/Android/android-sdk-linux/ 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: 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 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 /home/USER/Android/android-sdks/ to have it all in one place. Extract the Android NDK to /home/USER/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.x Download OpenSceneGraph-3.0.1 and extract it to /home/USER/Android/OpenSceneGraph-3.0.1/ Download the 3rd Party Dependencies and extract it to /home/USER/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/USER/Android/android-ndk-r7b export ANDROID_SDK=/home/USER/Android/android-sdks where USER is the username. (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/USER/Android/OpenSceneGraph-3.0.1/build cd /home/USER/Android/OpenSceneGraph-3.0.1/build This created a directory build in the OpenSceneGraph-directory. This is where we will place our build 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 After 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 /usr/local into the folders /usr/local/obj and /usr/local/include: sudo make install After this is finished, we are ready to start the eclipse project. Before starting eclipse, copy the folder osgAndroidExampleGLES1 from /home/USER/Android/OpenSceneGraph-3.0.1/examples to /home/USER/workspace/osgAndroidExampleGLES1 (or wherever else your eclipse workspace is). Start eclipse and go to New → Project and choose “Android Project“. Next, then choose „Create project from existing source“ and set the location to /home/USER/workspace/osgAndroidExampleGLES1 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 := /usr/local 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 cd /home/USER/workspace/osgAndroidExampleGLES1 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 $ANDROID_NDK/ndk-build Now that we built the native part of the Android OSG Viewer, go back to eclipse and run it. That's it. Using OpenGLES2 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 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 ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46357#46357 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org