There is an example in the NDK: Android-ndk-r10/samples/module-exports/jni
I see it.
———————————————————————————–
Pre-compiled libraries (shared and static) are supported starting with the R5 version. This means that in your app, you can include and use precompiled libraries.
The usefulness of this function
1. You want to distribute your own library to 3rd party NDK developers, but don't want to give them the source code.
2. You want to use your own precompiled library to speed up the project build process.
Declaring a pre-compiled library module
Each precompiled library must be declared as a separate module to the NDK build system.
Directory structure
Mylib --android.mk --libfoo.so
ANDROID.MK's Content
Local_path: = $ (call My-dir) include $ (clear_vars) Local_module: = foo-prebuiltlocal_src_files: = Libfoo.soinclude $ ( Prebuilt_shared_library)
Precautions
1. Each pre-compiled module must have a name, such as the name above is Foo-prebuilt
The module name can be different from the name of the precompiled library (for example, the name of the library is Libfoo, the module name is Foo-prebuild)
2. Set the path to the precompiled library that Local_src_files provides for you. Note that this path is relative to the Local_path. It is said that the source so is also found in the Local_path/lib directory.
Also: If you provide a library with multiple ABI versions, there is a bit of finesse, which is mentioned later.
3. Include prebuilt_shared_library (provide shared library); Or include Prebuilt_static_library (provides a static library)
Referencing the prepared precompiled module in other modules
Just add local_shared_libraries (or local_static_libraries) and declare it to your android.mk.
Local_path: = $ (call My-dir) include $ (clear_vars) Local_module: = foo-userlocal_src_files: = Foo-user.clocal_shared_ LIBRARIES: = foo-prebuilt#local_ldlibs: =-lm-lloginclude $ (build_executable)
The only thing to note is that the Reference module name (foo-prebuilt), not the library name (Libfoo)
Output header file for pre-compiled libraries
In real-world applications, FOO-USER.C relies on functions or variables declared in header files (foo.h) that are distributed with the same library file
In other words, the FOO-USER.C will have the following code
#include <foo.h>
When building your Foo-user module, you must provide the header file of the precompiled module and the containing path of the header file to the compiler.
Assuming that the header file loves you in the Include directory under the precompiled module directory, we can use the export in the android.mk of the precompiled module
Local_path: = $ (call My-dir) include $ (clear_vars) Local_module: = foo-prebuiltlocal_src_files: = Libfoo.solocal_export_ C_includes: = $ (Local_path)/includeinclude $ (prebuilt_shared_library)
Local_export_c_includes allows other reference modules to find the appropriate header file
Other reference modules, will be in their own android.mk with Local_c_include to find (as if not to declare this, Local_ldflags also do not)
Multiple Abi
Armeabi Target CPU is arm v5 TE or later architecture armeabi-v7a Target CPU is arm V7 or later architecture x86 MIPS
Need to modify the local_src_files defined in the precompiled module
Local_src_files: = $ (Target_arch_abi)/libfoo.so
Android NDK references pre-compiled dynamic-link libraries