This library seems not to be very Android friendly.
There is something weird going on with the bootstrap function (cdk/cmake/bootstrap.cmake) that seems to redefine C and CXX compilers, and I guess the OP tried to re-overwrite those overwritten values. One workaround could be using ninja as build system, in fact in the main CMakelists.txt file you can see a section:
```
# Note: Does not work well with Ninja -- not sure why
if(NOT CMAKE_GENERATOR MATCHES "Ninja")
bootstrap()
endif()
```
Regarding the libraries, it seems that only OpenSSL needs to be downloaded and compiled, while the others are shipped with the connector-cpp code and in general, it is usually preferable to use the versions that come with the source code for compatibility reason.
The protoc-executable you pass, given it's path, seems relative to the host machine. I wonder if the library WITH_PROTOBUF needs to be compiled for the target architecture, or it is just needed the protoc executable. The error message seems to indicate to me that an executable built for android is trying to load a host system library.
Even with this command,
```
${ANDROID_CMAKE}/cmake \
-G Ninja \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=34 \
-DANDROID_PLATFORM=android-34 \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=${ARCH} \
-DANDROID_NDK=${ANDROID_NDK_ROOT} \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_STL=c++_shared \
-DCMAKE_INSTALL_PREFIX=./android_libs \
-DWITH_SSL=${OPENSSL_DIR} \
-DOPENSSL_INCLUDE_DIR=${OPENSSL_DIR}/include \
-DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_DIR}/lib/libcrypto.so \
-DOPENSSL_SSL_LIBRARY=${OPENSSL_DIR}/lib/libssl.so \
-DWITH_ZSTD=ON \
-DWITH_LZ4=ON \
-DWITH_ZLIB=ON \
-DWITH_PROTOBUF=ON \
-DCMAKE_BUILD_TYPE=Release \
-DWITH_TESTS=OFF \
-DWITH_JDBC=OFF \
../..
```
Some things still not work. On the output of the config phase done by cmake you can see CMAKE_SYSTEM_VERSION: 1. Looks like the android platform value is ignored:
-- Looking for sys/types.h
-- Looking for sys/types.h - not found
-- Looking for stdint.h
-- Looking for stdint.h - not found
-- Looking for stddef.h
-- Looking for stddef.h - not found
-- Check size of wchar_t
-- Check size of wchar_t - failed
-- Setting up Protobuf.
== configuring external build of protobuf
-- sources at: /home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/cdk/extra/protobuf
-- generator: Ninja
-- option CMAKE_BUILD_TYPE: Release
-- option CMAKE_SYSTEM_NAME: Android
-- option CMAKE_SYSTEM_VERSION: 1
-- option CMAKE_SYSTEM_PROCESSOR: aarch64
-- option CMAKE_C_COMPILER: /home/bloom/Android/Sdk/ndk/28.0.12433566/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- option CMAKE_CXX_COMPILER: /home/bloom/Android/Sdk/ndk/28.0.12433566/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
When ninja builds, there are errors:
1) This looks like this struct is not defined, and I wonder if there is a standard workaround for that, given it seems related to the system header resolv.h
5/78] Building CXX object cdk/foundation/CMakeFiles/cdk_foundation.dir/socket_detail.cc.o
FAILED: cdk/foundation/CMakeFiles/cdk_foundation.dir/socket_detail.cc.o
/home/bloom/Android/Sdk/ndk/28.0.12433566/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android34 --sysroot=/home/bloom/Android/Sdk/ndk/28.0.12433566/toolchains/llvm/prebuilt/linux-x86_64/sysroot -DCONCPP_BUILD_SHARED -I/home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/cdk/include -I/home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/build/arm64-v8a/cdk/include -I/home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/cdk/extra/rapidjson/include -isystem /home/bloom/sw_develop/Android/libraries/connector-cpp/openssl/build/out/arm64-v8a/include -Wall -std=c++17 -std=c++17 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -O3 -DNDEBUG -fPIC -fPIC -fvisibility-ms-compat -Wall -DRAPIDJSON_HAS_CXX11_NOEXCEPT=1 -DRAPIDJSON_HAS_CXX11_RANGE_FOR=1 -DRAPIDJSON_HAS_CXX11_RVALUE_REFS=1 -MD -MT cdk/foundation/CMakeFiles/cdk_foundation.dir/socket_detail.cc.o -MF cdk/foundation/CMakeFiles/cdk_foundation.dir/socket_detail.cc.o.d -o cdk/foundation/CMakeFiles/cdk_foundation.dir/socket_detail.cc.o -c /home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/cdk/foundation/socket_detail.cc
/home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/cdk/foundation/socket_detail.cc:1097:22: error: variable has incomplete type 'struct __res_state'
1097 | struct __res_state state {};
| ^
/home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/cdk/foundation/socket_detail.cc:1097:10: note: forward declaration of '__res_state'
1097 | struct __res_state state {};
| ^
1 error generated.
2) This seems just a simple linking problem and it should be easy to fix linking the Android log library, but I tried adding find_package on one of the CMakeLists with no luck:
[4/78] cd /home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-s.../Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/cdk/cmake/ext/ext-build.cmake
FAILED: cdk/protocol/mysqlx/CMakeFiles/protobuf-build /home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/build/arm64-v8a/cdk/protocol/mysqlx/CMakeFiles/protobuf-build
cd /home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/build/arm64-v8a/cdk/protocol/mysqlx/protobuf && /home/bloom/Android/Sdk/cmake/3.30.5/bin/cmake -DBIN_DIR=/home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/build/arm64-v8a/cdk/protocol/mysqlx/protobuf -DCONFIG=Release -DOPTS=--parallel 20 -P /home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/cdk/cmake/ext/ext-build.cmake
== Running extrnal build at: /home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/build/arm64-v8a/cdk/protocol/mysqlx/protobuf (Release)
[1/2] Linking CXX executable runtime_output_directory/protoc-3.19.6.0
FAILED: runtime_output_directory/protoc-3.19.6.0
: && /home/bloom/Android/Sdk/ndk/28.0.12433566/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -std=c++17 -O3 -DNDEBUG protobuf-3.19.6/cmake/CMakeFiles/protoc.dir/__/src/google/protobuf/compiler/main.cc.o -o runtime_output_directory/protoc-3.19.6.0 protobuf-3.19.6/cmake/libprotoc.a protobuf-3.19.6/cmake/libprotobuf.a -llog && :
ld.lld: error: unable to find library -llog
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake Error at /home/bloom/sw_develop/Android/libraries/connector-cpp/mysql-connector-c++-9.1.0-src/cdk/cmake/ext/ext-build.cmake:55 (message):
External build failed: 1
I have a playground at
https://github.com/AndrewBloom/connector-cpp-android if anyone wants to attempt the compilation.