Android – Installing & using the Android NDK in Eclipse

androidandroid-ndkinstallation

I've been running the Android SDK for a while now in Eclipse (MAC OSX). I've downloaded the NDK and installed the C/C++ tools in Eclipse, but could anyone guide me on using the NDK? For example, do I just create an Android project like normal and build it with the NDK instead?

Really could do with a decent tutorial if anyone know of any.

EDIT: OK so I have the NDK installed now (I think) but does anyone have any idea how to use it? I got as far as this (taken from here):

Run Terminal

cd ~/android-ndk-1.5_r1

make APP=hello-jni

In order to run the hello-jni sample application, but I get an error in terminal saying:

Android NDK: APP variable defined to
unknown applications: hellojni
Android NDK: You might want to use
one of the following:
build/core/main.mk:81: *** Android
NDK: Aborting . Stop.

Any ideas why?

Best Solution

As simply as I can describe it, building an Android app from within Eclipse that uses the NDK requires two steps.

First, inside your terminal you need to run the NDK build script on your project. cd into the root of your project directory and then execute the ndk-build script within that directory.

For example:

cd ~/workspace/hello-jni
./~/android-ndk-1.5_r1/ndk-build

After doing this, you should see some output that results in the creation of a *.SO file within the obj directory within your project directory.

Once you have the *.SO file, the final step to building an application with the Android NDK through Eclipse is to build it with Eclipse like you would any other application and then deploy it for testing.

If you make any changes to the C/C++ code you'll need to repeat step one and regenerate your *.SO file before building and deploying your application from within Eclipse again.

I would like to note that by using the Android NDK your android apps are still based upon Java. They're just communicating with code written in C/C++ by way of the Java Native Interface.

Finally, I am not aware of any Eclipse plugins that will aid with NDK development. Everything I know about the NDK I have learned the official Android NDK documentation. Please feel free to comment and let me know if there anything I can clear up in my response.