Android cmakefile里面配置链接动态库和静态库时报错:missing and no known rule to make it
程序员文章站
2022-03-10 23:01:51
报错如下:* What went wrong:Execution failed for task ':app:externalNativeBuildDebug'.> Build command failed. Error while executing process D:\SDK\cmake\3.10.2.4988404\bin\cmake.exe with arguments {--build F:\AndroidProjectTest\Friend-test\app\.external...
报错如下:
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process D:\SDK\cmake\3.10.2.4988404\bin\cmake.exe with arguments {--build F:\AndroidProjectTest\Friend-test\app\.externalNativeBuild\cmake\debug\x86_64 --target meeting}
ninja: error: 'F:/AndroidProjectTest/Friend-test/app/src/main/cpp/libs/x86_64/libbylog.so', needed by 'F:/AndroidProjectTest/Friend-test/app/build/intermediates/cmake/debug/obj/x86_64/libmeeting.so', missing and no known rule to make it
CMake如下:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
set(SOURCE_DIR ${CMAKE_SOURCE_DIR})
#message("the project root dir: ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}")
# 动态库引入
#log
add_library(bylog SHARED IMPORTED)
set_target_properties(bylog
PROPERTIES
IMPORTED_LOCATION
${SOURCE_DIR}/libs/${ANDROID_ABI}/libbylog.so)
set(TARGET_LINK_MODULES ${TARGET_LINK_MODULES} bylog log)
#DHT
add_library(dht STATIC IMPORTED)
set_target_properties(dht
PROPERTIES
IMPORTED_LOCATION
${SOURCE_DIR}/libs/${ANDROID_ABI}/libdht.a)
set(TARGET_LINK_MODULES ${TARGET_LINK_MODULES} dht)
set(TARGET_INC_PATH ${TARGET_INC_PATH} ${SOURCE_DIR}/dht)
#QUIC
add_library(quic STATIC IMPORTED)
set_target_properties(quic
PROPERTIES
IMPORTED_LOCATION
${SOURCE_DIR}/libs/${ANDROID_ABI}/libquic.a)
set(TARGET_LINK_MODULES ${TARGET_LINK_MODULES} quic)
#源码
set(MEETING_TARGET_NAME meeting)
set(TARGET_SRC_FILES ${SOURCE_DIR}/ApplicationContext.cpp
${SOURCE_DIR}/common/utils.cpp)
#添加目标库 meeting
add_library(${MEETING_TARGET_NAME} SHARED ${TARGET_SRC_FILES})
target_include_directories(${MEETING_TARGET_NAME} PRIVATE ${SOURCE_DIR})
target_include_directories(${MEETING_TARGET_NAME} PRIVATE ${SOURCE_DIR}/common)
target_include_directories(${MEETING_TARGET_NAME} PRIVATE ${TARGET_INC_PATH})
target_link_libraries(${MEETING_TARGET_NAME} ${TARGET_LINK_MODULES})
报错的原因是,build.gradle里面没有添加红色部分,如下:
本文地址:https://blog.csdn.net/weixin_42713739/article/details/107161629