I suffered a loss when calling third-party so files in the C ++ code of Android NDK for the first time. put the so file in the libs/armeabi directory. If you did not expect an ndk-build, the so file will be deleted and a link error will be reported. it is found that NDK is called. so needs to be PREBUILT processing, the steps are as follows:
1. Create a prebuilt subdirectory under the project/jni directory (the directory name can be customized). 2. Put the third-party. so in prebuilt and create Android. mk. The content is as follows:
LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
LOCAL_MODULE: = xxx
LOCAL_SRC_FILES: = libxxx. so
Include $ (PREBUILT_SHARED_LIBRARY)
3. Add the following content to project/jni/Android. mk:
LOCAL_SHARED_LIBRARIES: = xxx
4. Add it at the end of project/jni/android. mk
Include $ (LOCAL_PATH)/prebuilt/Android. mk
5. Run cygwin and run $ NDK/ndk-build static library reference under the project directory.
Two days ago, I wanted to use jni to call some ready-made code. So I used NDK to compile the project. The Android. mk file is as follows:
View plainprint?
- LOCAL_PATH: =$ (CallMy-dir)
-
- Include$ (CLEAR_VARS)
-
- LOCAL_MODULE : =My_jni
- LOCAL_SRC_FILES: =My_jni.c
-
-
- LOCAL_STATIC_LIBRARIES: =Libstatic
-
- LOCAL_LDLIBS: =-Llog
-
- Include$ (BUILD_SHARED_LIBRARY)
Libstatic. a is the third-party static library that I want to call.
However, if a problem occurs, the system prompts that the function in the static library cannot be found, as shown below:
View plainprint?
- D:/WJR-WorkPlace/WorkSpace/Android/jni/my_jni.c: 172:UndefinedReferenceTo'_ Destroy'
_ Destroy is a function provided by a third-party static library.
I found a lot of information and failed to solve the problem. I finally solved the problem with the help of my colleagues because the static library link is incorrect and I changed android. mk
View plainprint?
- LOCAL_PATH: =$ (CallMy-dir)
-
- Include$ (CLEAR_VARS)
- LOCAL_MODULE : =Static
- LOCAL_SRC_FILES: =Libstatic.
- Include$ (PREBUILT_STATIC_LIBRARY)
-
- Include$ (CLEAR_VARS)
-
- LOCAL_MODULE : =My_jni
- LOCAL_SRC_FILES: =My_jni.c
-
- Local_static_libraries: =Static
-
- Local_ldlibs: =-Llog
-
- Include$ (Build_shared_library)