Compiling the latest OpenSSL for Android

Viewed 61396

I am trying to generate the shared library for the (.so) files of the OpenSSL1.0.1c for the Android. I found that they have added three options for compiling for the Android in the android script.

./Configure android-armv7  (or)
./Configure android-x86    (or)
./Configure android

once I configured for the OS and then try to compile, its throwing errors. Currently I am working x86 windows7 and installed Cygwin, Android sdk R20, Android NDK r8

sh-4.1$ make
making all in crypto...
make[1]: Entering directory `/cygdrive/d/SourceCodes/OpenSSL/openssl-1.0.1c/crypto'
gcc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -march=armv7-a -mandroid -I/include -B/lib -O3 -fomit-frame-pointer -Wall -DOPENSSL_BN_ASM_MONT -DOP
ENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DAES_ASM -DGHASH_ASM   -c -o cryptlib.o cryptlib.c
cc1: error: unrecognized command line option "-mandroid"
cryptlib.c:1:0: error: bad value (armv7-a) for -march= switch
<builtin>: recipe for target `cryptlib.o' failed
make[1]: *** [cryptlib.o] Error 1
make[1]: Leaving directory `/cygdrive/d/SourceCodes/OpenSSL/openssl-1.0.1c/crypto'
Makefile:278: recipe for target `build_crypto' failed
make: *** [build_crypto] Error 1
sh-4.1$

Please let me know if anyone faced the similar issue and got the solution for resolving the same.

13 Answers

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.

With NDK v22 and openssl-1.0.2o:

export PATH=$(echo -n $ANDROID_NDK/toolchains/llvm/prebuilt/*/bin):$PATH
./Configure android-x86 no-asm
make clean build_libs AR="llvm-ar r" RANLIB="llvm-ranlib" CC=i686-linux-android19-clang CFLAG="-fPIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -D__ANDROID_API__=19 -Os -fomit-frame-pointer -Wall -I$ANDROID_NDK_ROOT/sysroot/usr/include -I$ANDROID_NDK_ROOT/sysroot/usr/include/i686-linux-android"
mkdir -p x86/lib x86/include/openssl
cp lib*.a x86/lib
cp include/openssl/* x86/include/openssl

builds static libs for x86

Related