【发布时间】:2019-11-26 09:13:38
【问题描述】:
我有一些 C 代码必须集成到我的 Android 项目中。它取决于一个库 (.so),我也有 .h 文件。
我将 libs 和 include 目录复制到项目的 cpp 包中,以便于查找。
为了方便起见,我尝试从 Android Studio 提供的 HelloJNI 项目开始,并按照说明进行操作 here。
这是 CMakeLists.txt:
#given from HelloJNI
cmake_minimum_required(VERSION 3.4.1)
add_library(hello-jni SHARED
hello-jni.c)
# Include libraries needed for hello-jni lib
target_link_libraries(hello-jni
android
log)
#my own additions now:
add_library( # Specifies the name of the library.
libgdndk
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
IMPORTED)
set_target_properties( # Specifies the target library.
libgdndk
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
${CMAKE_BINARY_DIR}/libs/${ANDROID_ABI}/libgdndk.so )
include_directories(${CMAKE_BINARY_DIR}/inc/)
target_link_libraries( hello-jni libgdndk app-glue ${libgdndk} )
这会导致错误:
ninja: error: 'libs/armeabi-v7a/libgdndk.so', needed by 'C:/workspace/android/HelloJNI/app/build/intermediates/cmake/arm7/debug/obj/armeabi-v7a/libhello-jni.so', missing and no known rule to make it
【问题讨论】: