添加第一个库:
https://developer.android.com/studio/projects/add-native-code.html#create-sources
如果已经有一个库了,希望添加一个新的,如下例:
- 新建一个文件夹,如 native:
- 在该文件夹下添加一个 C/CPP 文件,如 native.cpp
- 在该 C/CPP 文件中添加
#include <jni.h>
- 在 CMakeList.txt 中添加如下代码:
#加一个 add_library
add_library( # Sets the name of the library.
native
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
../native/native.cpp)
#在原 target_link_libraries 中加入 native
target_link_libraries( # Specifies the target library.
native-lib
native
# Links the target library to the log library
# included in the NDK.
${log-lib})
- 同步
添加完成。