I want to build OpenSSL for Android, as a dependency of my C++-application which is built via Conan. The conan build (conan install /.../my_project -pr:h android34-armv8-clang-17-c++_shared -pr:b default --build=missing) otherwise works as expected.
android34-armv8-clang-17-c++_shared (target architecture) profile:
[settings]
os=Android
arch=armv8
compiler=clang
compiler.version=17
compiler.libcxx=c++_shared
build_type=Debug
os.api_level=34
[options]
[build_requires]
[buildenv]
ANDROID_NDK_HOME=/home/user/Android/Sdk/ndk/26.3.11579264
ANDROID_NDK=$ANDROID_NDK_HOME
ANDROID_NDK_ROOT=/home/user/Android/Sdk/ndk/26.3.11579264
ANDROID_SDK_ROOT=$ANDROID_HOME
ANDROID_NDK_VERSION=26.3.11579264
CC=/home/user/Android/Sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
CXX=/home/user/Android/Sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
RANLIB=/home/user/Android/Sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib
AR=/home/user/Android/Sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
[env]
ANDROID_NDK_HOME=/home/user/Android/Sdk/ndk/26.3.11579264
ANDROID_NDK_ROOT=/home/user/Android/Sdk/ndk/26.3.11579264
ANDROID_NDK=$ANDROID_NDK_HOME
ANDROID_SDK_ROOT=$ANDROID_HOME
ANDROID_NDK_VERSION=26.3.11579264
CC=/home/user/Android/Sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
CXX=/home/user/Android/Sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
RANLIB=/home/user/Android/Sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib
AR=/home/user/Android/Sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
[conf]
tools.android:ndk_path=/home/user/Android/Sdk/ndk/26.3.11579264/
Conan correctly identifies the dependencies (e.g. openssl/3.2.1 ) and starts a cross-build ("Cross-build from 'Linux:x86_64' to 'Android:armv8'").
The build for openssl then starts and seems to identify the target correctly as well:
openssl/3.2.1: using target: conan-Debug-Android-armv8-clang-17 -> linux-generic64
openssl/3.2.1: my %targets = (
"conan-Debug-Android-armv8-clang-17" => {
inherit_from => [ "linux-generic64" ],
cflags => add("-g"),
cxxflags => add("-g"),
lflags => add(""),
perlasm_scheme => "linux64",
},
);
openssl/3.2.1: Aggregating env generators
openssl/3.2.1: Calling build()
openssl/3.2.1: apply_conandata_patches(): No patches defined in conandata
openssl/3.2.1: Running: perl ./Configure "conan-Debug-Android-armv8-clang-17" shared --prefix=/ --libdir=lib --openssldir="/home/user/.conan/data/openssl/3.2.1/_/_/package/307503e24fa1e7276c553bf27b1fc9befa5ee61a/res" no-unit-test threads PERL=perl no-tests --debug -D__ANDROID_API__=34 -fPIC enable-fips no-md2 zlib --with-zlib-include="/home/user/.conan/data/zlib/1.3.1/_/_/package/023d2329c8205a068e7539cdd05ad94dd88a0fab/include" --with-zlib-lib="/home/user/.conan/data/zlib/1.3.1/_/_/package/023d2329c8205a068e7539cdd05ad94dd88a0fab/lib"
Configuring OpenSSL version 3.2.1 for target conan-Debug-Android-armv8-clang-17
Using os-specific seed configuration
...
OpenSSL has been successfully configured
...
So the configuration appears to work, but the build process later fails:
/home/user/Android/Sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -fPIC -pthread -g -g -fPIC -Wl,-z,defs -Wl,-znodelete -shared -Wl,-Bsymbolic -L/home/user/.conan/data/zlib/1.3.1/_/_/package/023d2329c8205a068e7539cdd05ad94dd88a0fab/lib \
-o providers/fips.so -Wl,--version-script=providers/fips.ld \
providers/fips/fips-dso-fips_entry.o \
providers/libfips.a -lz -ldl -pthread
ld.lld: error: /home/user/.conan/data/zlib/1.3.1/_/_/package/023d2329c8205a068e7539cdd05ad94dd88a0fab/lib/libz.a(adler32.c.o) is incompatible with elf64-x86-64
ld.lld: error: /home/user/.conan/data/zlib/1.3.1/_/_/package/023d2329c8205a068e7539cdd05ad94dd88a0fab/lib/libz.a(compress.c.o) is incompatible with elf64-x86-64
ld.lld: error: /home/user/.conan/data/zlib/1.3.1/_/_/package/023d2329c8205a068e7539cdd05ad94dd88a0fab/lib/libz.a(crc32.c.o) is incompatible with elf64-x86-64
ld.lld: error: /home/user/.conan/data/zlib/1.3.1/_/_/package/023d2329c8205a068e7539cdd05ad94dd88a0fab/lib/libz.a(deflate.c.o) is incompatible with elf64-x86-64
ld.lld: error: /home/user/.conan/data/zlib/1.3.1/_/_/package/023d2329c8205a068e7539cdd05ad94dd88a0fab/lib/libz.a(gzclose.c.o) is incompatible with elf64-x86-64
...
clang-17: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:25460: providers/fips.so] Error 1
make[1]: *** Waiting for unfinished jobs....
clang-17: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:26026: util/quicserver] Error 1
clang-17: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:5727: libcrypto.so.3] Error 1
make[1]: Leaving directory '/home/user/.conan/data/openssl/3.2.1/_/_/build/307503e24fa1e7276c553bf27b1fc9befa5ee61a/src'
make: *** [Makefile:3232: build_sw] Error 2
The problem is a mismatch between the compilation targets. The dependency zlib is compiled for armv8, which is correct, because that is the architecture of my target android phone. For some reason the build-process of OpenSSL expects it to be x86 and crashes because of that mismatch.
In the repository of OpenSSL there are multiple documents explaining the build process, NOTES_ANDROID.md, INSTALL.md and the configuration file 15-android.conf. I followed the instructions there, so the environment variable ANDROID_NDK_ROOT is set and I checked that -D__ANDROID_API__ is set to the right target API.
I think the problem is the target conan-Debug-Android-armv8-clang-17. It is automatically created by the conanfile of OpenSSL, which explicitly mentions that "Android targets are very broken".
Edit:
The problem seems to be very complex and might be caused by a problem with conan. Therefore I created a GitHub Issue at https://github.com/conan-io/conan-center-index/issues/25972
linux-x86_64/bin/clangshould be x64, then there should be scripts likelinux-x86_64/bin/aarch64-linux-android29-clangwhich call it with target specified. Are you sure the build for openssl identifies the target correctly? "linux-generic64" on your platform looks a lot like x64 to me...34-clangfrom your CC variable. Take a look at toolchain recipe.