Mixing Java and C/C++ Code

Calling a C/C++ function from Java is actually quite easy but requires several steps:

  1. The native method must be declared in your Java code.
  2. The Java Native Interface (JNI) glue layer needs to be implemented.
  3. Android makefiles have to be created.
  4. The native method must be implemented in C/C++.
  5. The native library must be compiled.
  6. The native library must be loaded.

It really is easy in its own twisted way. We will go through each one of these steps, and by the end of this section, you will know the basics of mixing Java and C/C++. We will discuss the more intricate details of the Android makefiles, which allow you to optimize your code even more, in later sections. Since the Android NDK exists for Linux, MacOS X, and ...

Get Pro Android Apps Performance Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.