我對Android和NDK/CMake很新穎。不過,我試圖將一個本地CMake庫嵌入到Android應用程序中。但是,這個庫依賴於OpenSSL。Android CMake:找不到OpenSSL
這就是爲什麼我下載了Android的預編譯版本的OpenSSL。
然而,當我嘗試同步的項目,我得到以下錯誤:
Could NOT find OpenSSL, try to set the path to OpenSSL root folder
in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES)
(found version "1.1.0f")
這裏是我的(最小的)項目結構
<app-name>
-app
- src
- main
- cpp
- library
- CMakeLists.txt
CMakeLists.txt
- distribution
- openssl
- armeabi
- include
- openssl
...
- lib
libcrypto.a, libssl.a
在我的build.gradle我定義以下:
externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
}
}
的/app/src/main/cpp/CmakeLists.txt如下所示:
cmake_minimum_required(VERSION 3.4.1)
set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../distribution)
set(OPENSSL_ROOT_DIR ${distribution_DIR}/openssl/${ANDROID_ABI})
set(OPENSSL_LIBRARIES "${OPENSSL_ROOT_DIR}/lib")
set(OPENSSL_INCLUDE_DIR ${OPENSSL_ROOT_DIR}/include)
message("OPENSSL_LIBRARIES ${OPENSSL_LIBRARIES}")
message("OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}")
find_package(OpenSSL REQUIRED)
add_subdirectory(library)
使用此:[鏈接](https://stackoverflow.com/questions/11896304/openssl-is-not-recognized-as-an-internal-or-external-command/44199907 #44199907)它會幫助你... –