Skip to content

Instantly share code, notes, and snippets.

@bertrandmartel
Last active August 22, 2024 09:23
Show Gist options
  • Save bertrandmartel/d964444f4a85c2598053 to your computer and use it in GitHub Desktop.
Save bertrandmartel/d964444f4a85c2598053 to your computer and use it in GitHub Desktop.
Build Curl for Android NDK

Build libcurl for android NDK

Libcurl requires openssl and zlib to be fully operationnal

  • Step 1 : cross compile zlib
  • Step 2 : cross compile openssl
  • Step 3 : cross compile curl with zlib/openssl external link

Prerequisites :

Build zlib for arch arm-linux-androideabi

  • get sources
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -xvzf zlib-1.2.8.tar.gz
cd zlib-1.2.8
  • build settings
INSTALLATION_PATH=/path/to/install_directory

export CC=arm-linux-androideabi-gcc
export CPP=arm-linux-androideabi-g++
export AR=arm-linux-androideabi-ar
export prefix=$INSTALLATION_PATH
  • build & install
./configure
make
make install

Build openSSL for arch arm-linux-androideabi

  • get sources
wget https://www.openssl.org/source/openssl-1.0.1p.tar.gz
tar -xvzf openssl-1.0.1p.tar.gz
  • build settings
#Delete all reference to arm-linux-androideabi arch in your path before pursuing, the following will do this for you

INSTALLATION_PATH=/path/to/install_directory

wget https://wiki.openssl.org/images/7/70/Setenv-android.sh
chmod 777 Setenv-android.sh
export ANDROID_NDK_ROOT=/path/to/ndk
change _ANDROID_API="android-18" to _ANDROID_API="android-21" in Setecn
. ./Setenv-android.sh
cd openssl-1.0.1p
perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=$INSTALLATION_PATH
  • build
make depend
make all
make install

Build curl for arch arm-linux-androideabi

  • build settings
#Before all, add standalone toolchain to your path if you dont (remove latter toolchain entry from openssl build and add the one you got from make-standalone.sh script)

INSTALLATION_PATH=/path/to/install_directory

export CROSS_COMPILE="arm-linux-androideabi"
export CPPFLAGS="-I/home/abathur/MyApplication/app/src/main/prebuild/include" #path to zlib and openssl header folder
export LDFLAGS="-L/home/abathur/MyApplication/app/src/main/prebuild" #path to zlib and openssl library folder
export AR=${CROSS_COMPILE}-ar
export AS=${CROSS_COMPILE}-as
export LD=${CROSS_COMPILE}-ld
export RANLIB=${CROSS_COMPILE}-ranlib
export CC=${CROSS_COMPILE}-gcc
export NM=${CROSS_COMPILE}-nm
export LIBS="-lssl -lcrypto"

./configure --host=${CROSS_COMPILE} --with-ssl --with-zlib --disable-ftp --disable-gopher --disable-file --disable-imap --disable-ldap --disable-ldaps --disable-pop3 --disable-proxy --disable-rtsp --disable-smtp --disable-telnet --disable-tftp --without-gnutls --without-libidn --without-librtmp --disable-dict
  • build & install
make

DESTDIR=$INSTALLATION_PATH

make install
@danoli3
Copy link

danoli3 commented May 19, 2021

Thank you *

@milinddeore
Copy link

Thanks @bertrandmartel
I would recommend these scripts, they are quite straight forward to compile. I tried with NDK v14b and its works quite well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment