RSS

Install OSG for Android On Ubuntu 13.04: Step-by-Step tutorials

24 Sep

Installation of essential tools and packages

  

Installation of open scene graph

     

Build the 1st Android OSG Example Application

  

Installation of essential tools and packages

    • Install Java
      sudo add-apt-repository ppa:webupd8team/java
      sudo apt-get update
      sudo apt-get install oracle-java8-installer
    • Install Android ADT (Eclipse + Android SDK)
      Goto
      http://developer.android.com/sdk/index.html
      Download appropriate zip files, e.g. 64 bit linux version
      Extract it to a folder, e.g. $HOME/ADT
    • Install Android NDK
      Goto http://developer.android.com/tools/sdk/ndk/index.html
      Download appropriate files, e.g. android-ndk-r9-linux-x86_64.tar.bz2
      Extract it to a folder, e.g. $HOME/ndk
    • Install cmake
      sudo apt-get install cmake
    • Install OpenGL
      sudo apt-get install freeglut3-dev
    • Install build-essential package (including g++)
      sudo apt-get install build-essential
    • Install 7zip
      sudo apt-get install p7zip-full
    • Install subversion (if you need to clone osg source code from repository)
      sudo apt-get install subversion libapache2-svn
    • Editor .bashrc file
      gedit ~/.bashrc
      Append two environement variables to the tail:
              export ANDROID_NDK=$HOME/ndk
              export ANDROID_SDK=$HOME/ADT/sdk

       

Installation of open scene graph

    • Create two folders “build” & “osginstall” (the name can be whatever you like, be consistent) inside the OSG source folder:

$HOME/Android/OpenSceneGraph-3.0.1/build
$HOME/Android/OpenSceneGraph-3.0.1/osginstall

    • Open a terminal and change directory to the “build” fold    cd $HOME/Android/OpenSceneGraph-3.0.1/build
    • Run below command for OSG with OpenGL ES 1.x, remember to substitute the string “osginstall” if you have used different folder names created above

      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 

    • For osg Android GLES2, refer to this link to run cmake with different parameters
    • Run below command to compile and build all pieces of the code that needs to be recompiled. This takes very long time (1+ hours) to finish.
          make


    • Run below command to generate the executables and other required files
      make install

Build the 1st Android OSG Example Application

    • Open Eclipse
    • Menu New > Import > Android > Existing Android Code Into Workspace
  • Browse to the osg source code folder
          $HOME/Android/OpenSceneGraph-3.0.1/examples/osgAndroidExampleGLES1
  • Tick “Copy project into workspace” option, and you will see a project is imported to workspace\osgViewer folder

    • In Eclipse project browser, expand the folder jni
    • Open Android.mk in the editor, make the following changes and save:

Change line 7 to:   OSG_ANDROID_DIR := /home/USER/osgViewer
Change line 21 to:  LOCAL_DLIBS := -llog -lGLESv1_CM -ldl -lz -lgnustl_static

    • Open a terminal, and change directory to

cd $HOME/workspace/osgViewer

    • Type below command

$ANDROID_NDK/ndk-build

Here come the most tricky parts: when you run this command, you will see tons of errors and warnings, follow below instructions to proceed:

 


Warnings or Errors:
         jni/OsgMainApp.hpp:21:18: fatal error: osg/GL: No such file or directory
Actions:
In Android.mk,
after LOCAL_C_INCLUDES:= $(OSG_ANDROID_DIR)/include
Add below line:
         LOCAL_C_INCLUDES +=/home/david/Android/OpenSceneGraph-3.0.1/include

 


Warnings or Errors:
        include/osg/GL:17:22: fatal error: osg/Config: No such file or directory

Actions: In Android.mk, add below line
        LOCAL_C_INCLUDES +=/home/david/Android/OpenSceneGraph-3.0.1/build/include

 


Warnings or Errors:

        jni/osgNativeLib.cpp: In function ‘void Java_osg_AndroidExample_osgNativeLib_loadObject  (JNIEnv*, jobject, jstring)’: in jni/osgNativeLib.cpp:78:70: error: converting ‘false’ to pointer type for argument 2 of ‘char const* _JNIEnv::GetStringUTFChars(jstring, jboolean*)’ [-Werror=conversion-null]   

Actions: Go to corresponding lines, e.g Line 78  in osgNativeLib.cpp
change const char *nativeAddress = env->GetStringUTFChars(address, false); 

       to        const char *nativeAddress = env->GetStringUTFChars(address, NULL);
Do so for all such errors.

 


Warnings or Errors:
        bin/ld: error: cannot find -losgdb_dds
Actions:
Copy folder /home/david/Android/OpenSceneGraph-3.0.1/build/obj
→               
/home/david/workspace/osgViewer/obj

 


Warnings or Errors:

       bin/ld: error: cannot find -lgnustl_static
Actions:
Copy below two folders
        /home/david/ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a
        /home/david/ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeab
→    
/home/david/workspace/osgViewer/obj/local/armeabi-v7a
        /home/david/workspace/osgViewer/obj/local/armeabi

 


Re-run the command
       $ANDROID_NDK/ndk-build

Results:

Connect Android real devices to Ubuntu, in Eclipse, run the osgViewer Project, you should see below screens:

svn checkout http://svn.openscenegraph.org/osg/OpenSceneGraph-Data/trunk/

    • Copy some files, e.g. cow.osg to the android device
    • In the android device, use ASTRO File Manager to browse the cow.osg that is just copied
    • Long press on the cow.osg file, and get the file’s address

    • In the osgViewer Android App, press the menu “…”, then press menu item “load object” 

    • type in the cow.osg’s path:

    • Press accept button in the alert dialog, then press “Center View” button in the activity’s UI:

    • Use touch to zoom and rotate, yeah! Success!


Enjoy and comments are welcome!

Advertisements
 
6 Comments

Posted by on September 24, 2013 in Linux, osg, Programming

 

Tags: , , , , , , , , , , , ,

6 responses to “Install OSG for Android On Ubuntu 13.04: Step-by-Step tutorials

  1. xx

    November 5, 2014 at 9:40 am

    Picture can’t display?

     
  2. xinyustudio

    November 5, 2014 at 10:22 am

    worked fine here. Where are you located? Is wordpress blocked in your locale?

     
  3. 陈斌

    January 2, 2015 at 9:48 am

    非常感谢这个详细的说明!

     
  4. Célian

    September 19, 2015 at 12:23 am

    Hello ! Thank you for this !

    Just Maybe replace
    Change line 7 to: OSG_ANDROID_DIR := /home/USER/osgViewer
    by
    Change line 7 to: OSG_ANDROID_DIR := /home/USER/workspace/osgViewer

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: