Tag Archives: Tips & Tricks - Page 2

Configuring NDK with Eclipse (II)

Since the Android NDK r4 it’s delivered with a script file helping the build (appropriatelly called ndk-build), I was interested how this can be integrated in the Eclipse’s build system. The purpose of this is is to have both the C++ and the Java code in same project folder (for easier handing with version control system) and to allow building the application from inside the Eclipse, without reverting to command line.

The most of the steps are the same as in the previous post about integrating NDK with Eclipse.

First, we need to convert the project to C++ project:

  • right click on project root,then select New Project -> Other -> C++ -> Convert to C++
  • check C++ project, choose Makefile and for toolchain choose other.
  • accept to open the C++ perspective.

Until this, the project was converted to C++ project. We now need to set up the input and output folders for C++ build:

  • create the libs, jni and obj folders. Set the output folders to libs and obj, then set the source folder to jni (in project properties, C++ General)

And finally we need to set up a new builder:

  • while in C++ perspective, open project properties and choose builders, then uncheck everything related to CDT builder.
  • create a new builder of type program.
  • in the window with builder properties: first text field contains the ndk-build script location, second text field contains project location and the last one should contain -C ${build_project}

And that’s it. You should be able to build your project, Clean and eclipse will run the required builders in order to build both java and C++ code and finally create the APK file.
Before first build it is possible there will be some errors, but those will disappear after the build.