Yet another day that Eclipse made a joke to me 🙂 – yeah, we are getting friendlier 😉

My Macbook gave a “startup disk almost full” warning while Eclipse was on. The warning was because of some other reason though. So i quitted each application and restarted my macbook and eclipse. While starting Eclipse it gave an error pop up, but I clicked “OK” so fast that I didn’t notice what happened exactly. Then, there was nothing on the UI, just two buttons and the top menu for sure.. I thought that this was a problem of workspace and loaded it again. It loaded and built the workspace without any problems. I followed this process from the bottom info bar of Eclipse. But again, there was nothing on the UI. So what could be the problem, workspace was loaded and built but no UI?? Then I checked the top menu, if I can enable something or not…  Window->Open Perspective-> Java (default) saved me! It was just a problem of perspective 😉 

Lesson learned: Change your perspective if  you really want to solve a problem 😉


Looks too much like a draft, but I hope it summarizes the flow of onCreate () for you, too.


After preparing the IDE, I am digging into the ImageTargets example… Well implemented and quite complicated with all callbacks and asynchronous processes. While trying to understand it, I remembered myself to practice:

  • Android application cycle
  • GLSurfaceView and Renderer classes
  • OpenGL ES 2.0 (I am completely a newbie on this)
  • AsyncTask, Runnable, synchronized block, etc… (topics related to processes and threaded – which is always a total nightmare for me on any platform using any programming language)
  • NDK (I am completely a newbie on this, too)

It feels like starting from scratch, but I’ll try my best until my deadline! To get help from colleagues, I first need to know on which topic I need help 🙂

Currently I am trying to build a schematic from the project flow. It is becoming more clear how I can edit this code, but I need a little more time. As soon as I finish it, I’ll post it here!!

After I started using native code in Android projects, I wondered if I can edit and build the c/c++ code from Eclipse. Because every time I needed to edit the native code, it had to do it in XCode and build it on the terminal using ndk-build command. After some research I found that NDK build can be integrated into Eclipse using CDT plugin. Follow the steps from one of these nice web sites :

If you followed everything, now your Eclipse should recognize c/c++ code and you can use Eclipse just as some other native development IDE (Visual Studio, XCode…). Unfortunately everything didn’t work out this smooth for me. I received a build error as follows:

**** Build of configuration Default for project AndroidNDK1Sample ****


Cannot run program “ndk-build”: Unknown reason
Error: Program “ndk-build” is not found in PATH


**** Build Finished ****

As you know from my former posts, my PATH variable is not this short and minimal (if I may say :)) Basically, c/c++ builder of Eclipse doesn’t recognize my PATH variable (FYI, I defined PATH in .bash_profile. I am not handy with environment variable declarations in MacOS X. That’s why I had some trouble.. Here is someone who had the same problem as me: If you have the same inconsistency in your PATH variable, follow this entry in StackOverflow:

Were you lucky? I wasn’t :/ My solution to this issue ( after spending some afternoon on this, yuck 😦 ) is as follows:

  • Right click your project and open properties
  • Under c/c++ build, go to environment and add a new variable to override PATH having the values in your actual PATH variable (In MacOS X, open terminal and write command env. Copy the PATH string).
  • Clean your project
  • and your PATH is fixed (But only for this project)

Here is a nice tutorial that I followed as the basic step :

Some notes about NDK:

  • Use it if your code is processor bound
  • If you have already c / c++ code that you want to use in your project, you don’t need to rewrite them in Java. Just use NDK.
  • JNI: Java Native Interface. It defines a way for managed code to interact with native (c/c++) code.
  • JNIEnv and JavaVM are pointers to pointers to function tables.
  • Android allows only one JavaVM to be active at the same time.
  • Native Functions receive JNIEnv as the first argument.
  • You cannot share JNIEnv between threads. If needed, share JavaVM and use GetEnv.
  • c and c++ definitions are different. Beware!
  • Debugger is only available for Android 2.2 and newer platforms.


  1. write native code (c/c++)
  2. add to jni folder of your project ( if there is no folder named jni, create it)
  3. call the native code from the java code. load the library.
  4. create makefile:
  5. ndk-build from terminal
  6. refresh project and run

… here is the simple answer:

As written in the Vuforia SDK forum by the admin:

Dividing your project between Java and native code:
Using the sample projects (especially ImageTargets) as a starting point, you can write most of your application-specific code at the native level. This especially includes any OpenGL rendering. Sometimes, however, it is useful to leverage the Android SDK for features such as UI controls, video playback, networking, etc. Also, if your application includes sound it is necessary to implement this in Java, as the NDK does not currently have access to device audio playback.

Positioning your virtual objects on top of the trackable:
There are two matrices you need to position your OpenGL objects on top of (or in relation to) the target. First, you’ll need the projection matrix from the tracker, which can be constructed using the Tool::getProjectionGL method (see ImageTargets.cpp for usage). Second, you’ll need the pose matrix from a visible trackable, which is calculated each camera frame and retrieved with the trackable.getPose() method. See What is a pose? in the thread QCAR SDK Basics for more information on using this matrix.

Scaling your trackable in OpenGL space:
At some point you may want to size your 3D objects to fit the trackable, translate objects within the bounds of the trackable, etc. Here it’s useful to know the size of the trackbale in OpenGL space. The ImageTarget and Marker classes have a size() function that returns the width and height of the trackable for this purpose.

Rendering 3D content in various formats (obj, collada, etc.):
The QCAR SDK does not provide a loader or renderer for 3D formats. The samples, however, do show how to load and render a static model from a header file. You are free to use loaders/renderers from outside sources, but this forum does not provide support for any particular renderer.

To get more detail: -> Vuforia Architecture