What you need to know to compile jni under Android source code~

The following are just some of my own summaries. Welcome to discuss. There are many examples of compiling jni

through NDK. Here I only summarize the compilation

of android source code 1. Compile the so package under the android source code environment. The compiled .so package will not be automatically given Add lib, NDK compilation will automatically add lib, even if LOCAL_MODULE:= there is no lib in front of the name in the Android.mk file, NDK will automatically add lib to you. So when NDK compiles, the name of the so package compiled from the Android.mk file can be added The lib can also be omitted, but the source code must be compiled with


2. The difference between the system application and the user application

   The apk generated after compiling the project under package/app will be burned to the mobile phone under system/app, and these apk will be used as the system Application, the .so libraries used by system applications are all under system/lib, if not, an error will occur. This is why the library generated by compiling jni under the source code will be placed in out/target/product/xxxxxxxx_xx_m0/system/lib
   The user application will default to the lib folder of the application's data/data directory to find .so, if it is not found, it will be report an error. The current premise is that your system system/lib does not have the same so file.


3. The difference between adb push and adb install

   Adb push can specify the installation directory. For example, after executing "adb push xxx.apk system/app", xxx.apk is installed in the system/app directory. At this time, it is the system application
   adb install. The software installed with this command is located in the data/app directory, which is the user application.


4. When we modify the jni file in the system application, after you flash the machine, there will be the so file you need in the system/lib of the system. If you don't want to flash the machine, you can also put *.so under system\lib for calling by adb push *.so \system\lib, because the system/lib in the system without flashing is not generated just now. .so


5. If we don't have jni file but only .so, the system application needs to call .so under system/lib, so we need to preset this .so file to out/target/product/ when compiling xxxxxxxx_xx_m0 / system / lib in the
include $ (CLEAR_VARS)
LOCAL_MODULE: = libfp_gf_mp
LOCAL_SRC_FILES: = ../libs/arm64-v8a/libfp_gf_mp.so
LOCAL_MODULE_TAGS: = optional
LOCAL_MODULE_SUFFIX: = .so
LOCAL_PROPRIETARY_MODULE: = to true
LOCAL_MODULE_CLASS: = SHARED_LIBRARIES the
include $ ( BUILD_PREBUILT)

6. Use the .so library directly. Step
   1. The third-party so file or the so file compiled by others, you can put it directly under libs/armeabi

   2. Add the dependency LOCAL_JNI_SHARED_LIBRARIES to Android.mk in the main folder: = libuserbookpatcher_jni

   3. If it is a system application, you need to preset the .so file in the Android.mk of jni to system/lib

   Note: In the program, use the jni file to generate .so without preset, because it will be directly generated inside system/ In the lib but in the Android.mk of the main folder, add the dependency LOCAL_JNI_SHARED_LIBRARIES := libuserbookpatcher_jni


7. Add
# Use the folloing include to make our test apk.
include $(call all-makefiles- under, $(LOCAL_PATH))
will compile Android.mk in all subdirectories of the current project directory

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326340234&siteId=291194637