java - android studio 使用JNI 构建c/c++,但c/c++ 需要另一个lib.a,如何解决

标签 java android c++ android-ndk java-native-interface

关于android studio。当我编辑 JNI 以使用 c/c++ 代码时,但 c/c++ 代码使用另一个 lib .a,所以我如何编辑我的 CMakeList.txt,请帮助我,如果你擅长使用 Android Studio enter image description here

这是我的 CMakeList.txt 当我做项目时。它说“/../../mips64el-linux-android/bin\ld: 找不到-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})

最佳答案

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

为了更容易理解,这里是一个编辑过的脚本:

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

关于java - android studio 使用JNI 构建c/c++,但c/c++ 需要另一个lib.a,如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47573145/

相关文章:

c++ - 我如何打印到 LLVM 中的字符串

java - 我们可以使用 MongoRespository 进行 findByNameAndPassword() 这种类型的查询吗?

java - 一种更好的方法来处理文件上传中在套接字上读取的意外 EOF?

Android - 在 HttpsURLConnection 中传递 OAuth1

java - 单击通知中的按钮不会触发广播接收器

c++ - 即使使用多核上下文,是否有任何 std::chrono 线程安全保证?

java - 防止 JPanel 在 repaint() 调用时重绘背景

java - LibGDX:如何在FitViewport的黑条区域中绘制?

android - 无法停止/重启 AsyncTask

c++ - 将字符串打印到屏幕上后更改 C++ 中的字符串