r0n9
r0n9

Reputation: 2729

How to build OpenSSL 1.0.2 for Android 6.0.1?

I am working on an application which uses the OpenSSL library. I am trying to run the app on Android emulator without replacing the OpenSSL by boringssl. So I downloaded the AOSP source tree and I am currently able to lunch emulator.

To add OpenSSL, I git clone the openssl into external/openssl.

Based on the openssl project http://github.com/eighthave/openssl-android I added different Android.mk files in the external/openssl, external/openssl/apps, external/openssl/crypto and external/openssl/ssl folder, added android-config.mk, and Application.mk to external/openssl folder. But when I run mm, the compiler spits an error:

build/core/base_rules.mk:217: *** external/openssl/crypto: MODULE.TARGET.SHARED_LIBRARIES.libcrypto already defined by external/boringssl.
build/core/ninja.mk:155: recipe for target 'out/build-aosp_arm-mmm-external_openssl_Android.mk.ninja' failed
make: *** [out/build-aosp_arm-mmm-external_openssl_Android.mk.ninja] Error 1
make: Leaving directory '/home/rong/projects/Android/src'

Any one knows how to build OpenSSL in AOSP?


AOSP environment:

Development environment:

Upvotes: 2

Views: 1545

Answers (1)

Saad Bilal
Saad Bilal

Reputation: 1837

Follow these instructions may help :)

  1. Download Android NDK (version ndk-r13b) from this url:

    https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip

  2. Extract NDK to /home/Android.

  3. Download the cross compilation setup script from this URL:

    https://wiki.openssl.org/images/7/70/Setenv-android.sh

  4. Make following changes in the Setenv-android.sh script:

    a: Add the following line to the start of the script:

    ANDROID_NDK_ROOT=/home/Android/android-ndk-r13b

    b: Modify _ANDROID_NDK="android-ndk-r13".

    c: Modify _ANDROID_EABI="arm-linux-androideabi-4.9"

    d: Modify _ANDROID_API="android-23"

  5. Download the openssl (version 1.0.2n) from this url:

    https://www.openssl.org/source/old/1.0.2/openssl-1.0.2n.tar.gz

  6. Extract the downloaded tarball.

  7. Open new terminal window and navigate to extracted directory.

  8. Move the Setenv-android.sh script to this directory and execute the following commands:

    chmod a+x Setenv-android.sh
    source ./Setenv-android.sh
    
  9. Run the following command (to configure OpenSSL sources to build for Android):

    ./Configure shared android
    
  10. Execute following command to build libcrypto and libssl shared libraries.

    make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" build_libs
    
  11. Let the build complete successfully.

Upvotes: 1

Related Questions