Mixing Java and C/C++ Code
Calling a C/C++ function from Java is actually quite easy but requires several steps:
- The native method must be declared in your Java code.
- The Java Native Interface (JNI) glue layer needs to be implemented.
- Android makefiles have to be created.
- The native method must be implemented in C/C++.
- The native library must be compiled.
- 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.