I'm including OpenSSL in my Android project using david-hoze/build-openssl-android: Builds openssl 1.1.0h with android ndk r17..
This is my setup: Android Studio 3.2 NDK version: 18.0.5002713
This is my app's build.gradle
file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
def my_openssl_dir = getRootDir().toString() + "/build-openssl-android/openssl-lib"
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.my-company.my-app"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++17 -frtti -fexceptions"
arguments '-DANDROID_STL=c++_shared'
arguments '-DMY_OPENSSL_DIR=' + my_openssl_dir
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
jniLibs.srcDirs = [
]
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'org.jetbrains.kotlin:kotlin-reflect:1.2.30'
}
This is my CMakeLists.txt
file:
cmake_minimum_required(VERSION 3.4.1)
include_directories( src/main/cpp/
)
add_library( # Sets the name of the library.
my-library
SHARED
src/main/cpp/my-code.cpp
)
find_library (log-lib log)
add_library(libcrypto STATIC IMPORTED)
set_target_properties(libcrypto PROPERTIES IMPORTED_LOCATION
${MY_OPENSSL_DIR}/${ANDROID_ABI}/libcrypto.a)
add_library(libssl STATIC IMPORTED)
set_target_properties(libssl PROPERTIES IMPORTED_LOCATION
${MY_OPENSSL_DIR}/${ANDROID_ABI}/libssl.a)
target_include_directories(nativ PRIVATE
${MY_OPENSSL_DIR}/${ANDROID_ABI}/include
)
target_link_libraries( # Specifies the target library.
my-library
libcrypto
libssl
${log-lib}
)
And I'm getting these errors while compiling:
Build command failed. Error while executing process /home/david/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/david/dev/android/MyApplication/app/.externalNativeBuild/cmake/debug/x86_64 --target my-library} [1/1] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/x86_64/libnativ.so FAILED: : && /home/david/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=x86_64-none-linux-android21 --gcc-toolchain=/home/david/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64 --sysroot=/home/david/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem /home/david/Android/Sdk/ndk-bundle/sysroot/usr/include/x86_64-linux-android -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++17 -frtti -fexceptions -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /home/david/Android/Sdk/ndk-bundle/platforms/android-21/arch-x86_64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/home/david/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86_64 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnativ.so -o ../../../../build/intermediates/cmake/debug/obj/x86_64/libnativ.so CMakeFiles/my-library.dir/src/main/cpp/my-code.cpp.o /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libcrypto.a /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a /home/david/Android/Sdk/ndk-bundle/platforms/android-21/arch-x86_64/usr/lib64/liblog.so -latomic -lm "/home/david/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86_64/libc++_shared.so" && : /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_ciph.o):ssl_ciph.c:function do_load_builtin_compressions_ossl_: error: undefined reference to 'COMP_get_type' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_ciph.o):ssl_ciph.c:function do_load_builtin_compressions_ossl_: error: undefined reference to 'COMP_get_name' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_ciph.o):ssl_ciph.c:function ssl_cipher_get_evp: error: undefined reference to 'FIPS_mode' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_ciph.o):ssl_ciph.c:function ssl_cipher_get_evp: error: undefined reference to 'EVP_enc_null' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_ciph.o):ssl_ciph.c:function ssl_create_cipher_list: error: undefined reference to 'FIPS_mode' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_ciph.o):ssl_ciph.c:function ssl_create_cipher_list: error: undefined reference to 'FIPS_mode' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_ciph.o):ssl_ciph.c:function SSL_COMP_add_compression_method: error: undefined reference to 'COMP_get_type' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_ciph.o):ssl_ciph.c:function SSL_COMP_get_name: error: undefined reference to 'COMP_get_name' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_conf.o):ssl_conf.c:function cmd_VerifyCAFile: error: undefined reference to 'X509_STORE_load_locations' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_conf.o):ssl_conf.c:function cmd_ChainCAPath: error: undefined reference to 'X509_STORE_load_locations' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_conf.o):ssl_conf.c:function cmd_ChainCAFile: error: undefined reference to 'X509_STORE_load_locations' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_conf.o):ssl_conf.c:function cmd_VerifyCAPath: error: undefined reference to 'X509_STORE_load_locations' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_read: error: undefined reference to 'ASYNC_WAIT_CTX_new' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_peek: error: undefined reference to 'ASYNC_WAIT_CTX_new' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_write: error: undefined reference to 'ASYNC_WAIT_CTX_new' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_shutdown: error: undefined reference to 'ASYNC_WAIT_CTX_new' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_CTX_new: error: undefined reference to 'FIPS_mode' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function ssl_clear_cipher_ctx: error: undefined reference to 'COMP_CTX_free' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function ssl_clear_cipher_ctx: error: undefined reference to 'COMP_CTX_free' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_CTX_set_default_verify_dir: error: undefined reference to 'X509_LOOKUP_hash_dir' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_CTX_set_default_verify_file: error: undefined reference to 'X509_LOOKUP_file' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_free: error: undefined reference to 'ASYNC_WAIT_CTX_free' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_get0_peer_scts: error: undefined reference to 'OCSP_response_get1_basic' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_get0_peer_scts: error: undefined reference to 'OCSP_resp_count' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_get0_peer_scts: error: undefined reference to 'OCSP_resp_get0' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_get0_peer_scts: error: undefined reference to 'OCSP_SINGLERESP_get1_ext_d2i' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function ssl_validate_ct: error: undefined reference to 'CT_POLICY_EVAL_CTX_new' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function ssl_validate_ct: error: undefined reference to 'CT_POLICY_EVAL_CTX_set1_cert' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function ssl_validate_ct: error: undefined reference to 'CT_POLICY_EVAL_CTX_set1_issuer' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function ssl_validate_ct: error: undefined reference to 'CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function ssl_validate_ct: error: undefined reference to 'CT_POLICY_EVAL_CTX_set_time' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function ssl_validate_ct: error: undefined reference to 'CT_POLICY_EVAL_CTX_free' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function ssl_validate_ct: error: undefined reference to 'CT_POLICY_EVAL_CTX_free' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_get_all_async_fds: error: undefined reference to 'ASYNC_WAIT_CTX_get_all_fds' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_get_changed_async_fds: error: undefined reference to 'ASYNC_WAIT_CTX_get_changed_fds' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_get_current_compression: error: undefined reference to 'COMP_CTX_get_method' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_get_current_expansion: error: undefined reference to 'COMP_CTX_get_method' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_lib.o):ssl_lib.c:function SSL_CTX_set_default_verify_paths: error: undefined reference to 'X509_STORE_set_default_paths' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_rsa.o):ssl_rsa.c:function SSL_use_certificate_file: error: undefined reference to 'PEM_read_bio_X509' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_rsa.o):ssl_rsa.c:function SSL_use_RSAPrivateKey_file: error: undefined reference to 'PEM_read_bio_RSAPrivateKey' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_rsa.o):ssl_rsa.c:function SSL_CTX_use_certificate_file: error: undefined reference to 'PEM_read_bio_X509' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_rsa.o):ssl_rsa.c:function SSL_CTX_use_RSAPrivateKey_file: error: undefined reference to 'PEM_read_bio_RSAPrivateKey' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_rsa.o):ssl_rsa.c:function SSL_CTX_use_certificate_chain_file: error: undefined reference to 'PEM_read_bio_X509_AUX' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_rsa.o):ssl_rsa.c:function SSL_CTX_use_certificate_chain_file: error: undefined reference to 'PEM_read_bio_X509' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_rsa.o):ssl_rsa.c:function SSL_use_certificate_chain_file: error: undefined reference to 'PEM_read_bio_X509_AUX' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_rsa.o):ssl_rsa.c:function SSL_use_certificate_chain_file: error: undefined reference to 'PEM_read_bio_X509' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(statem_clnt.o):statem_clnt.c:function ssl3_check_cert_and_algorithm: error: undefined reference to 'X509_certificate_type' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(statem_srvr.o):statem_srvr.c:function tls_process_cert_verify: error: undefined reference to 'X509_certificate_type' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(t1_lib.o):t1_lib.c:function ssl_get_auto_dh: error: undefined reference to 'BN_get_rfc3526_prime_3072' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(t1_lib.o):t1_lib.c:function ssl_get_auto_dh: error: undefined reference to 'BN_get_rfc3526_prime_8192' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function SSL_srp_server_param_with_username: error: undefined reference to 'SRP_Calc_B' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function SSL_set_srp_server_param_pw: error: undefined reference to 'SRP_get_default_gN' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function SSL_set_srp_server_param_pw: error: undefined reference to 'SRP_create_verifier_BN' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function srp_generate_server_master_secret: error: undefined reference to 'SRP_Verify_A_mod_N' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function srp_generate_server_master_secret: error: undefined reference to 'SRP_Calc_u' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function srp_generate_server_master_secret: error: undefined reference to 'SRP_Calc_server_key' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function srp_generate_client_master_secret: error: undefined reference to 'SRP_Verify_B_mod_N' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function srp_generate_client_master_secret: error: undefined reference to 'SRP_Calc_u' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function srp_generate_client_master_secret: error: undefined reference to 'SRP_Calc_x' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function srp_generate_client_master_secret: error: undefined reference to 'SRP_Calc_client_key' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function srp_verify_server_param: error: undefined reference to 'SRP_check_known_gN_param' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(tls_srp.o):tls_srp.c:function SRP_Calc_A_param: error: undefined reference to 'SRP_Calc_A' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl3_record.o):ssl3_record.c:function ssl3_do_uncompress: error: undefined reference to 'COMP_expand_block' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl3_record.o):ssl3_record.c:function ssl3_do_compress: error: undefined reference to 'COMP_compress_block' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(s3_enc.o):s3_enc.c:function ssl3_change_cipher_state: error: undefined reference to 'COMP_CTX_free' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(s3_enc.o):s3_enc.c:function ssl3_change_cipher_state: error: undefined reference to 'COMP_CTX_new' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(s3_enc.o):s3_enc.c:function ssl3_change_cipher_state: error: undefined reference to 'COMP_CTX_free' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(s3_enc.o):s3_enc.c:function ssl3_change_cipher_state: error: undefined reference to 'COMP_CTX_new' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_asn1.o):ssl_asn1.c:SSL_SESSION_ASN1_seq_tt: error: undefined reference to 'UINT32_it' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_asn1.o):ssl_asn1.c:SSL_SESSION_ASN1_seq_tt: error: undefined reference to 'INT32_it' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_asn1.o):ssl_asn1.c:SSL_SESSION_ASN1_seq_tt: error: undefined reference to 'ZINT64_it' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_asn1.o):ssl_asn1.c:SSL_SESSION_ASN1_seq_tt: error: undefined reference to 'ZINT64_it' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_asn1.o):ssl_asn1.c:SSL_SESSION_ASN1_seq_tt: error: undefined reference to 'ZINT32_it' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_asn1.o):ssl_asn1.c:SSL_SESSION_ASN1_seq_tt: error: undefined reference to 'ZUINT64_it' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_asn1.o):ssl_asn1.c:SSL_SESSION_ASN1_seq_tt: error: undefined reference to 'ZUINT64_it' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_cert.o):ssl_cert.c:function SSL_add_dir_cert_subjects_to_stack: error: undefined reference to 'OPENSSL_DIR_read' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_cert.o):ssl_cert.c:function SSL_add_dir_cert_subjects_to_stack: error: undefined reference to 'OPENSSL_DIR_end' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(ssl_cert.o):ssl_cert.c:function ssl_build_cert_chain: error: undefined reference to 'X509_verify_cert_error_string' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(t1_enc.o):t1_enc.c:function tls1_change_cipher_state: error: undefined reference to 'COMP_CTX_new' /home/david/dev/android/MyApplication/build-openssl-android/openssl-lib/x86_64/libssl.a(t1_enc.o):t1_enc.c:function tls1_change_cipher_state: error: undefined reference to 'COMP_CTX_new' clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
Would appreciate your help.