How to package the. So file in APK
There are two methods,
1 is added to the Android. mk file.
Local_jni_shared_libraries: = libxxx
In this way, ndk will automatically package libxxx into APK during compilation;
In the youapk/lib/directory.
2. Create an application directory
Libs/armeabi
Directory, and then copy libxxx. So to this directory,
In this way, the ndk will automatically package libxxx. So into the APK.
In the youapk/lib/directory.
In the code, use
System. loadlibrary ("XXX ");
You can load this dynamic library.
Note that you only need to write the parameter XXX. You do not need to write libxxx or libxxx. So.
Another note is that the system. loadlibrary function will search for the libxxx. So file in the following path:
/System/lib
/Data/You APK package/lib
However, if libxxx. So still depends on other. So files, such as libyyy. So, system. loadlibrary will only
Find it in the/system/lib directory. If it is not found, it will not automatically go to/data/You APK package/lib
Continue searching. At this time, an error will be reported if the dynamic library is not found;
The solution is to load libyyy. So before load libxxx. So, as follows:
System. loadlibrary ("yyy ");
System. loadlibrary ("XXX ");
Bytes -------------------------------------------------------------------------------------------------
Premise: the so file is compiled in the source code and exists in the intermediate file of the compilation output. For example, the libtest. So file must be in the out/target/product/generic/obj/lib/libtest. So
In this way, write the Android. mk File
Add the following assignment statement:
Local_jni_shared_libraries: = libtest
You can.
For how to enable the compilation system to automatically add other resource files to the APK during compilation, refer to compile system files.
Build/CORE/package. mk
The compilation process of the local_jni_shared_libraries field.