Android Studio使用JNI来构建C/C ,但是C/C 需要另一个lib.a,如何解决

android studio use JNI to build c/c++ ,but the c/c++ need another lib.a, how to solve

本文关键字:lib 何解决 解决 另一个 JNI 使用 Studio 构建 Android 但是      更新时间:2023-10-16

关于Android Studio。当我编辑JNI以使用C/C 代码,但是C/C 代码使用另一个lib .a,那么我如何编辑我的cmakelist.txt,请帮助我,如果您擅长使用Android Studioenter Image Description

这是我的cmakelist.txt当我做项目时。它说"/../../mips64el-linux-android/bintroid/bin d:找不到-lwebsockets"

cmake_minimum_required(VERSION 3.4.1)
aux_source_directory(src/main/cpp/android_src/common FILE_COMMON)
aux_source_directory(src/main/cpp/android_src FILE_SRC)
aux_source_directory(src/main/cpp/ FILE_CPP)
SET(ALL_FILE ${FILE_CPP} ${FILE_SRC} ${FILE_CPP})
INCLUDE_DIRECTORIES(src/main/cpp/cpp_include)
#LINK_DIRECTORIES(src/main/cpp/cpp_lib)
add_library( websockets STATIC IMPORTED)
set_target_properties(websockets PROPERTIES IMPORTED_LOCATION src/main/cpp/cpp_lib/libwebsockets.a)
add_library( # Sets the name of the library.
             #native-lib
             SkylightWebSocket
             # Sets the library as a shared library.
             SHARED
             # Provides a relative path to your source file(s).
             #src/main/cpp/native-lib.cpp
             ${ALL_FILE})

find_library( # Sets the name of the path variable.
              log-lib
              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )
target_link_libraries( # Specifies the target library.
                       #native-lib
                       SkylightWebSocket
                       # Links the target library to the log library
                       # included in the NDK.
                       libwebsockets.a ${log-lib})

而不是 libwebsockets.a ,在target_link_libraries()语句中使用 websockets

使其更容易理解,这是一个编辑的脚本:

add_library( Q STATIC IMPORTED)
set_target_properties(Q PROPERTIES IMPORTED_LOCATION src/main/cpp/cpp_lib/libwebsockets.a)
add_library( # Sets the name of the library.
         #native-lib
         SkylightWebSocket
         # Sets the library as a shared library.
         SHARED
         # Provides a relative path to your source file(s).
         #src/main/cpp/native-lib.cpp
         ${ALL_FILE})
target_link_libraries( # Specifies the target library.
                   #native-lib
                   SkylightWebSocket
                   # Links the target library to the log library
                   # included in the NDK.
                   Q log)

请注意,使用NDK, log 库是定义的,您根本不需要find_library