Using a library in multiple projects with import-module
You may often need to use a library in multiple projects.
You can put the library in each of the project's jni
folders and build them separately. However, it is troublesome to maintain multiple copies of the same library. For example, when there is a new release of the library and you want to update the library, you will have to update each copy of the library.
Fortunately, Android NDK provides a feature to allow us maintain a library module outside a NDK project's main source tree and import the module with simple commands in the Android.mk
file. Let's discuss how to import a module in this recipe.
How to do it...
The following steps describe how to declare and import a module outside of a project's jni
folder:
Create an Android application named
ImportModule
with native support. Set the package name ascookbook.chapter8.importmodule
. Please refer to the Loading native libraries and registering native methods recipe of Chapter 2, Java...