title: include openssl library on native android project
body: <p>I want to create wrapper module to openssl library for android that will use most of the main functions for security.</p>
  
  <p>I know there are people that say they already did it and publish thier work on github but for security reasons we can't use it.</p>
  
  <p>I compiled the openssl library to android and add to the CMakeList.txt as described here:
  <a href="https://developer.android.com/studio/projects/configure-cmake#add-other-library" rel="nofollow noreferrer">https://developer.android.com/studio/projects/configure-cmake#add-other-library</a></p>
  
  <p>My steps that i have made :
  1. I download from here: <a href="https://www.openssl.org/source/" rel="nofollow noreferrer">https://www.openssl.org/source/</a> version 1.1.1c<br>
  2. Compiled sucessfully:  </p>
  
  <pre><code>export ANDROID_NDK_HOME=/home/user/Android/Sdk/ndk-bundle
  PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
  ./Configure android-arm64
  make
  </code></pre>
  
  <ol start="3">
  <li>I put the entire folder here:<br>
  Project/app/src/main/cpp/openssl-1.1.1c</li>
  </ol>
  
  <p>4.thats how the CMakeList looks like:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.4.1)
  set(CMAKE_VERBOSE_MAKEFILE ON)
  add_library(openssl-wrapper-lib
          SHARED
          openssl-c-wrapper.cpp)
  
  #===v===v===v===v===v===v===openssl-include===v===v===v===v===v===v===
  add_library(
          crypto
          SHARED
          IMPORTED
  )
  
  set_target_properties(
          crypto
          PROPERTIES IMPORTED_LOCATION
          ${CMAKE_CURRENT_SOURCE_DIR}/openssl-1.1.1c/libcrypto.so
  )
  
  include_directories(openssl-1.1.1c/include)
  #===^===^===^===^===^===^===openssl-include===^===^===^===^===^===^===
  
  find_library(log-lib
          log)
  
  target_link_libraries( # Specifies the target library.
          openssl-wrapper-lib
          crypto
          ${log-lib})
  </code></pre>
  
  <p>the error when i build is this:</p>
  
  <pre><code>Error while executing process /home/user/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/user/AndroidStudioProjects/EncryptionModule/app/.externalNativeBuild/cmake/debug/x86_64 --target openssl-wrapper-lib}
  [1/1] Linking CXX shared library /home/user/AndroidStudioProjects/EncryptionModule/app/build/intermediates/cmake/debug/obj/x86_64/libopenssl-wrapper-lib.so
  FAILED: : &amp;&amp; /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=x86_64-none-linux-android21 --gcc-toolchain=/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security  -v -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libopenssl-wrapper-lib.so -o /home/user/AndroidStudioProjects/EncryptionModule/app/build/intermediates/cmake/debug/obj/x86_64/libopenssl-wrapper-lib.so CMakeFiles/openssl-wrapper-lib.dir/openssl-c-wrapper.cpp.o  /home/user/AndroidStudioProjects/EncryptionModule/app/src/main/cpp/openssl-1.1.1c/libcrypto.so /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21/liblog.so -latomic -lm &amp;&amp; :
  Android (5220042 based on r346389c) clang version 8.0.7 (https://android.googlesource.com/toolchain/clang b55f2d4ebfd35bf643d27dbca1bb228957008617) (https://android.googlesource.com/toolchain/llvm 3c393fe7a7e13b0fba4ac75a01aa683d7a5b11cd) (based on LLVM 8.0.7svn)
  Target: x86_64-none-linux-android21
  Thread model: posix
  InstalledDir: /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin
  Found candidate GCC installation: /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x
  Found candidate GCC installation: /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x
  Selected GCC installation: /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x
  Candidate multilib: .;@m64
  Selected multilib: .;@m64
   "/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld" --sysroot=/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot -z now -z relro --hash-style=gnu --hash-style=both --enable-new-dtags --eh-frame-hdr -m elf_x86_64 -shared -o /home/user/AndroidStudioProjects/EncryptionModule/app/build/intermediates/cmake/debug/obj/x86_64/libopenssl-wrapper-lib.so /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21/crtbegin_so.o -L/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/lib/linux/x86_64 -L/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x -L/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/lib/../lib64 -L/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21 -L/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android -L/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/lib -L/home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib --exclude-libs libgcc.a --exclude-libs libatomic.a --build-id --warn-shared-textrel --fatal-warnings --no-undefined -z noexecstack -soname libopenssl-wrapper-lib.so CMakeFiles/openssl-wrapper-lib.dir/openssl-c-wrapper.cpp.o /home/user/AndroidStudioProjects/EncryptionModule/app/src/main/cpp/openssl-1.1.1c/libcrypto.so /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21/liblog.so -latomic -lm -Bstatic -lc++ -Bdynamic -lm -lgcc -ldl -lc -lgcc -ldl /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21/crtend_so.o
  /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: /home/user/AndroidStudioProjects/EncryptionModule/app/src/main/cpp/openssl-1.1.1c/libcrypto.so: incompatible target
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.
  
  </code></pre>
  
  <p>please help me understand what am I doing wrong</p>