首先,这是我的错误。

Build command failed.
Error while executing process /Users/{user}/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/{user}/Desktop/android/app/.externalNativeBuild/cmake/debug/arm64-v8a --target native-lib}
ninja: error: 'src/main/jniLibs/zlib/arm64-v8a/lib/libz.a', needed by '../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so', missing and no known rule to make it

我为每个ARCH(armeabi,armeabi-v7a,arm64-v8a,x86,x86_64)都有一个静态链接的预构建zlib.a库,并像这样放置该库。
app/src/main/jniLibs/zlib/${ANDROID_ABI}/include/zlib.h
app/src/main/jniLibs/zlib/${ANDROID_ABI}/lib/libz.a

这是我的CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)

add_library(native-lib SHARED src/main/cpp/native-lib.cpp)

add_library(libz STATIC IMPORTED)

set_target_properties(libz PROPERTIES IMPORTED_LOCATION src/main/jniLibs/zlib/${ANDROID_ABI}/lib/libz.a)

include_directories(src/main/jniLibs/zlib/${ANDROID_ABI}/include)

find_library(log-lib log)

target_link_libraries(native-lib libz ${log-lib})

在Java文件中
static {
    System.loadLibrary("libz");
    System.loadLibrary("native-lib");
}

我对这个问题一无所知。好像还好我不触摸build.gradle,对吗?我想念什么?怎么了

最佳答案

属性IMPORTED_LOCATION应该是绝对路径

使用${CMAKE_CURRENT_SOURCE_DIR}引用当前正在处理的CMakeLists.txt的目录:

set_target_properties(libz PROPERTIES
  IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/zlib/${ANDROID_ABI}/lib/libz.a)

07-26 04:00