Question

Installing & using the Android NDK in Eclipse

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?

 45  85796  45
1 Jan 1970

Solution

 24

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.

2012-04-14

Solution

 12

Native development and debugging support came into Eclipse environment as of ADT version 20. http://tools.android.com/recent/usingthendkplugin

  • Set path to NDK from Eclipse Preferences -> Android -> NDK
  • Right-click on your project and choose Android Tools -> Add Native Support

developer.android.com states you also need Cygwin.

http://developer.android.com/tools/sdk/ndk/index.html#Contents

Required development tools

  • For all development platforms, GNU Make 3.81 or later is required. Earlier versions of GNU Make might work but have not been tested.
  • A recent version of awk (either GNU Awk or Nawk) is also required.
  • For Windows, Cygwin 1.7 or higher is required. The NDK will not work with Cygwin 1.5 installations.
2013-09-21