Android JNI学习-使用第三方SO库

https://david1840.github.io/2018/12/03/Android-JNI学习-使用第三方SO库/

CMakeList.txt
在CMake中将LibTest.so导入工程

cmake_minimum_required(VERSION 3.4.1)

add_library( # Sets the name of the library.
             UseSo

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/jni/UseSo.c )
             
#导入第三方so包,并声明为 IMPORTED 属性,指明只是想把 so 导入到项目中
add_library( Test
             SHARED
             IMPORTED )
             
#指明 so 库的路径,CMAKE_SOURCE_DIR 表示 CMakeLists.txt 的路径             
set_target_properties(
             Test
             PROPERTIES IMPORTED_LOCATION
             ${CMAKE_SOURCE_DIR}/src/main/jniLibs/armeabi-v7a/libTest.so )

#指明头文件路径,不然会提示找不到 so 的方法
include_directories(src/main/jni/)

find_library(log-lib

              log )

target_link_libraries( # Specifies the target library.
                       UseSo

                       Test

                       ${log-lib} )

build.gradle

ndk {
    abiFilters 'armeabi-v7a'
}
posted @ 2024-03-20 11:06  源世  阅读(7)  评论(0编辑  收藏  举报