How to package prebuilt shared library inside an APK
In order to prebuild your native library you have to
- Create
jni
folder in your project folder - Create
libs
folder in your project folder Add
Adnroid.mk
make file to the jni folder, it should looks like this:LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_LDLIBS := -llog LOCAL_MODULE := Test LOCAL_SRC_FILES := Test.cpp include $(BUILD_SHARED_LIBRARY)
Note 1: Test.cpp
is the main library source file containing implementation of native methods. You can add more sources as a space separated list.
Note 2: Do not include headers, they are included automatically.
Note 3: If you need to enable C++ STL, then create another make file - Application.mk
, add it to the jni
folder and set APP_STL := stlport_static
flag in it.
Then you will have to set up a builder. Refer to this article for how to do that:
After these steps, the builder will create your library in the libs
folder which will be automatically packed into the apk when building the whole application.
Note: Your library name should be lowercase, it is a Linux convention. The "lib" prefix will be automatically added, so the final library name will be libtest.so.