一般来说有四种情况:动态库(.so),静态库(.a),NDK自带的库(eg. liblog),编写的源文件(c/c++文件):
distribution_DIR 为libs目录
set(distribution_DIR ../../../../libs)
1. 动态库:
add_library(
x264
SHARED
IMPORTED
)
set_target_properties(
x264
PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/armeabi/libx264.a
)
2. 静态库:
add_library(
x264
STATIC
IMPORTED
)
set_target_properties(
x264
PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/armeabi/libx264.a
)
3. NDK自带库:(使用find_library)
find_library(
log-lib
#从ndk中查找log库
log
)
4. c/c++文件:
add_library(
native-lib
src/main/cpp/native-lib.cpp
)
链接所有的库
target_link_libraries
( # Specifies the target library.
native-lib
#Links the target library to the log library
# included in the NDK.
${log-lib}
)