The android toolchain is broken for OpenSSL since #780
currently our generated toolchain .github/toolchains/android-ndk-api-35-arm64-v8a-libcxx14.cmake looks as follows
# toolchain file generated by set_matrix.py, do not modify!
set(CMAKE_SYSTEM_NAME "Android")
set(CMAKE_SYSTEM_VERSION "35") # API level
set(CMAKE_ANDROID_ARCH_ABI "arm64-v8a")
set(CMAKE_ANDROID_NDK "$ENV{ANDROID_NDK}") # provided by GitHub
string(COMPARE EQUAL "${CMAKE_ANDROID_NDK}" "" _is_empty)
if(_is_empty)
message(FATAL_ERROR
"Environment variable 'ANDROID_NDK' not set"
)
endif()
# ANDROID macro is not defined by CMake 3.7+, however it is used by
# some packages like OpenCV
# (https://gitlab.kitware.com/cmake/cmake/merge_requests/62)
add_definitions("-DANDROID")
set(CMAKE_ANDROID_STL_TYPE "c++_static") # LLVM libc++ static
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -stdlib=libc++")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
@olliwang provided a (for him) working toolchain in #815 (comment)
This toolchain was modified based on the original Android toolchain
# Copyright (c) 2018, Ruslan Baratov
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# For the latest version of this file and working example see:
# For the example and for the latest version of this file check:
# * https://github.com/forexample/android-studio-with-hunter
# Hunter need stand-alone toolchain that will not depend
# on any ANDROID_* variables:
# * https://docs.hunter.sh/en/latest/overview/customization/toolchain-id.html
# To achieve this we need to make a 3 steps:
# * Lock CMake variables that coming from Gradle build
# * Include original Android toolchain from NDK
# * Add any custom user variables
# STEP 1: Lock variables from Gradle build
set(ANDROID_ABI "@ANDROID_ABI@")
set(ANDROID_PLATFORM "@ANDROID_PLATFORM@")
set(ANDROID_STL "@ANDROID_STL@")
set(CMAKE_ANDROID_ARCH_ABI "@CMAKE_ANDROID_ARCH_ABI@")
set(CMAKE_ANDROID_STL_TYPE "c++_static")
set(CMAKE_SYSTEM_NAME "Android")
set(CMAKE_SYSTEM_VERSION "@CMAKE_SYSTEM_VERSION@")
# STEP 2: Include original toolchain
# Original toolchain file will be saved in variable:
# * _ORIGINAL_TOOLCHAIN_FILE
if("@_ORIGINAL_TOOLCHAIN_FILE@" STREQUAL "")
# Variable not set, initial project configuration.
# Path to original Android NDK toolchain saved in CMAKE_TOOLCHAIN_FILE.
if("@CMAKE_TOOLCHAIN_FILE@" STREQUAL "")
message(FATAL_ERROR "Unexpected: CMAKE_TOOLCHAIN_FILE is empty")
endif()
if(NOT EXISTS "@CMAKE_TOOLCHAIN_FILE@")
message(FATAL_ERROR "File not found: '@CMAKE_TOOLCHAIN_FILE@'")
endif()
set(_original_toolchain_file "@CMAKE_TOOLCHAIN_FILE@")
else()
set(_original_toolchain_file "@_ORIGINAL_TOOLCHAIN_FILE@")
endif()
set(
_ORIGINAL_TOOLCHAIN_FILE
"${_original_toolchain_file}"
CACHE
PATH
"Original Android NDK toolchain"
)
if(NOT "${_ORIGINAL_TOOLCHAIN_FILE}" STREQUAL "${CMAKE_CURRENT_LIST_FILE}")
include("${_ORIGINAL_TOOLCHAIN_FILE}")
endif()
# STEP 3: Fix Android NDK
if ("@_CMAKE_ANDROID_NDK@" STREQUAL "" AND
NOT "@CMAKE_ANDROID_NDK@" STREQUAL "")
set(
_CMAKE_ANDROID_NDK
"@CMAKE_ANDROID_NDK@"
CACHE
PATH
"Original Android NDK"
)
set(CMAKE_ANDROID_NDK "@CMAKE_ANDROID_NDK@")
elseif("${CMAKE_ANDROID_NDK}" STREQUAL "")
set(CMAKE_ANDROID_NDK "@_CMAKE_ANDROID_NDK@")
endif()
# STEP 4: Tweak CMake Android variables
set(CMAKE_SYSTEM_VERSION "${ANDROID_NATIVE_API_LEVEL}")
# STEP 5: Custom user variables
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
The values of the template variables in his environment are the following
@ANDROID_ABI@: arm64-v8a
@ANDROID_PLATFORM@: android-26
@ANDROID_STL@: c++_static
@CMAKE_ANDROID_ARCH_ABI@: arm64-v8a
@CMAKE_ANDROID_NDK@: /Users/username/Library/Android/sdk/ndk/28.2.13676358
@CMAKE_TOOLCHAIN_FILE@: /Users/username/Developer/proj/src/android/app/.cxx/Debug/6nb1j5q5/arm64-v8a/shared/nanoi/nanoi/generated/toolchain.cmake
@CMAKE_SYSTEM_VERSION@: 26
@_CMAKE_ANDROID_NDK@: /Users/username/Library/Android/sdk/ndk/28.2.13676358
@_ORIGINAL_TOOLCHAIN_FILE@: /Users/username/Library/Android/sdk/ndk/28.2.13676358/build/cmake/android.toolchain.cmake
The android toolchain is broken for OpenSSL since #780
currently our generated toolchain
.github/toolchains/android-ndk-api-35-arm64-v8a-libcxx14.cmakelooks as follows@olliwang provided a (for him) working toolchain in #815 (comment)
The values of the template variables in his environment are the following