Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile OpenSSL 1.1.0 for Android

I'm trying to compile openssl-1.1.0 on Android by cygwin follow by this guidance:

Compiling the latest OpenSSL for Android

But it's failed, this is the error :

crypto/aes/aes_ecb.c:10:20: fatal error: assert.h: No such file or directory
 #include <assert.h>

I'm using Android-ndk-r12b, Win10, cygwin 64 bit.

This is my pre-config before compiling:

export NDK=~/android-ndk-r12b
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-21 --toolchain=arm-linux-androideabi-4.9 --install-dir=`pwd`/android-toolchain-arm
export TOOLCHAIN_PATH=`pwd`/android-toolchain-arm/bin
export TOOL=arm-linux-androideabi
export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL}
export CC=$NDK_TOOLCHAIN_BASENAME-gcc
export CXX=$NDK_TOOLCHAIN_BASENAME-g++
export LINK=${CXX}
export LD=$NDK_TOOLCHAIN_BASENAME-ld
export AR=$NDK_TOOLCHAIN_BASENAME-ar
export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib
export STRIP=$NDK_TOOLCHAIN_BASENAME-strip
export ARCH_FLAGS="-mthumb"
export ARCH_LINK=
export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions "
export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export LDFLAGS=" ${ARCH_LINK} "
./Configure android
PATH=$TOOLCHAIN_PATH:$PATH make

Please help to tell me where I'm wrong

EDIT:

Follow by jww's suggestion, I try with https://wiki.openssl.org/index.php/Android

I changed some config in setenv-android.sh into:

-_ANDROID_NDK="android-ndk-r12b"
-_ANDROID_EABI="arm-linux-androideabi-4.9"
-_ANDROID_API="android-21"

To generate valid toolchains, I add "windows-x86_64" into for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86" Now it's:

for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86" "windows-x86_64"
do
....
done

+Build openssl-1.1.0:

Error:

$ perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
Can't open Makefile.org: No such file or directory.

EDIT 2:

I follow the wiki update by jww and it runs smoothly until this command:

arm-linux-androideabi-gcc -I /usr/local/ssl/include my_prog.c -o my_prog.exe -L /usr/local/ssl/lib -lssl -lcrypto

If I use $ANDROID_TOOCHAIN/arm-linux-androideabi-gcc -I /usr/local/ssl/include my_prog.c -o my_prog.exe -L /usr/local/ssl/lib -lssl -lcrypto , it doesn't understand -I and my_prog.c

I want to build openssl-1.1.0 for android but I don't know how to fix it. Please help

like image 227
kairen Avatar asked Sep 22 '16 13:09

kairen


People also ask

How do I set up OpenSSL?

Go to Advanced > Environment Variable. Set OPENSSL_CONF and Path variables. Open the command prompt using 'Windows' + 'r' then type 'cmd' to open command prompt. Type openssl version command on CLI to ensure OpenSSL is installed and configured on your Windows machine.

What is Openssldir?

OpenSSL is a very important library, widely used in numerous open source and closed source applications. This library has an internal directory tree that is used to locate the configuration file and this directory is called OPENSSLDIR.


1 Answers

I was trying to build OpenSSL 1.1.0g for Android with

android NDK android-ndk-r16b, centOS 6.9 64 bit OS.

as per https://wiki.openssl.org/index.php/Android

and had the same problem

crypto/aes/aes_ecb.c:10:20: fatal error: assert.h: No such file or directory
 #include <assert.h>

After searching, I found that Updated NDK android-ndk-r16b has updated the sysroot to android-ndk-r16b/sysroot which contains the include directories but no library.

So the include path and the library path has changed

but the setenv-android.sh set the sysroot as

export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"

But this is valid for android-ndk-r13b

I can successfully build the OpenSSL with android-ndk-r13b.

like image 126
iOS-Developer84 Avatar answered Oct 07 '22 13:10

iOS-Developer84