Tistory View

Android Develop/helper

android prebuilt curl library

What should I do? 2021. 12. 22. 10:04

I just need a http downloader to use on android NDK, also ssl is not required on my app.

so. I Search prebuilt curl library in google. but, most compiled version are not matched on my app. something conflict OpenSSL, something not works, and so on. After all, I decide to compile curl source code to use on my app.


How to compile the curl source code.

Below link explains How to compile, android compiling also explained. but Its explaination is mismatched to my ndk version



build and install curl from source

how to install curl and libcurl Installing Binary Packages Lots of people download binary distributions of curl and libcurl. This document does not describe how to install curl or libcurl using such a binary package. This document describes how to compile,


So, I modified "exports" from above links. I tried compiling, and it produced libcurl.a files.



Error on My App.

First. I encountered error message while linking my app like below.

libcurl.a(libcurl_la-mprintf.o):mprintf.c:function curl_mprintf: error: undefined reference to 'stdout'
libcurl.a(libcurl_la-multi.o):multi.c:function curl_multi_fdset: error: undefined reference to '__FD_SET_chk'
libcurl.a(libcurl_la-url.o):url.c:function Curl_init_userdefined: error: undefined reference to 'stdin'
libcurl.a(libcurl_la-url.o):url.c:function Curl_init_userdefined: error: undefined reference to 'stderr'
libcurl.a(libcurl_la-if2ip.o):if2ip.c:function Curl_if2ip: error: undefined reference to 'getifaddrs'
libcurl.a(libcurl_la-if2ip.o):if2ip.c:function Curl_if2ip: error: undefined reference to 'freeifaddrs'
libcurl.a(libcurl_la-netrc.o):netrc.c:function parsenetrc: error: undefined reference to 'fgets_unlocked'

std* is not found... hm.. and What is getifaddrs...

I found this error was caused by compiler api version 29, my app is started from api 19. so I changed android compiler version to api21, [below api21 compilers are not exist in "android-ndk-r21"]. I retried with api21 ndk compiler.


Second, I encountered error messages while linking my app like below. TOO.... hm..

libcurl.a(libcurl_la-multi.o):multi.c:function curl_multi_fdset: error: undefined reference to '__FD_SET_chk'

"Standard in-out-error" relative error messages were eliminated, but I still got error on my app[minAPI 19].

__FD_SET_chk function(?) is introduced in API 21. api 19 devices have no this function.


If You change minSkVersion to 21 or higher, above error messages will be eliminated.



Modify to work on below API 21

I modified multi.c file in lib path on source code.

lib/multi.c : line 1061 and 1068

    FD_SET(sockbunch[i], read_fd_set);
Replace With.........
__FDS_BITS(fd_set*,read_fd_set)[__FDELT(sockbunch[i])] |= __FDMASK(sockbunch[i]);

line 1068 is write_fd_set

FD_SET is defined in header <select.h>

#define __FD_SET(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] |= __FDMASK(fd))

Recompile and Test... Yes It works.



I attached prebuilt curl libraries in this article Two versions, one is api21 or higher, and Other is below api21



Below api21 version. NOSSL (Modified version)


This files was tested on below devices.

Galaxy Note4                               armeabi-v7a     32bits     api23

Galaxy S6 Edge                             arm64-v8a       64bits     api24

Chinese Intel android                     x86                 32bits     api19

LD player 64bits(emulater)               x86_64            64bits     api25?






API 21 or higher, NOSSL (Not Modified)





API 21 or higher with OpenSSL



Not modified with SSL Version, These Files are not tested. But maybe works..



OpenSSL for below API 21(Modified)

This Files are required for linking above curl


64bit files are for API21 in this File. Don't warry 64bit android were introduce in 2019(?), so most 64bit device versions are equal or higher than API-21




"Configure" results in my case

Compile machine : Ubuntu 20.04.2 LTS/64bits on virtual machine.

Host setup:       aarch64-unknown-linux-android
  Install prefix:   /usr/local
  Compiler:         ~~~~~/android_ndk/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi29-clang
   CFLAGS:          -Qunused-arguments -Os
   LIBS:            -lz

  curl version:     7.80.0
  SSL:              no      (--with-{openssl,gnutls,nss,mbedtls,wolfssl,schannel,secure-transport,mesalink,amissl,bearssl,rustls} )
  SSH:              no      (--with-{libssh,libssh2})
  zlib:             enabled
  brotli:           no      (--with-brotli)
  zstd:             no      (--with-zstd)
  GSS-API:          no      (--with-gssapi)
  GSASL:            no      (libgsasl not found)
  TLS-SRP:          no      (--enable-tls-srp)
  resolver:         POSIX threaded
  IPv6:             enabled
  Unix sockets:     enabled
  IDN:              no      (--with-{libidn2,winidn})
  Build libcurl:    Shared=no, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  Code coverage:    disabled
  SSPI:             no      (--enable-sspi)
  ca cert bundle:   no
  ca cert path:     
  ca fallback:      
  LDAP:             no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
  LDAPS:            no      (--enable-ldaps)
  RTSP:             enabled
  RTMP:             no      (--with-librtmp)
  PSL:              no      (libpsl not found)
  Alt-svc:          enabled (--disable-alt-svc)
  HSTS:             no      (--enable-hsts)
  HTTP1:            enabled (internal)
  HTTP2:            no      (--with-nghttp2, --with-hyper)
  HTTP3:            no      (--with-ngtcp2, --with-quiche)
  ECH:              no      (--enable-ech)
  Features:         AsynchDNS IPv6 Largefile UnixSockets alt-svc libz

Compile command

example for armeabi-v7a

export NDK=~/android_ndk/android-ndk-r21
export HOST_TAG=linux-x86_64
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG
export AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar
export AS=$TOOLCHAIN/bin/arm-linux-androideabi-as
export CC=$TOOLCHAIN/bin/armv7a-linux-androideabi21-clang
export CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi21-clang++
export LD=$TOOLCHAIN/bin/arm-linux-androideabi-ld
export RANLIB=$TOOLCHAIN/bin/arm-linux-androideabi-ranlib
export STRIP=$TOOLCHAIN/bin/arm-linux-androideabi-strip

./configure --host aarch64-linux-android --with-pic --disable-shared  --without-ssl


Source code




SSL Version NOTE

By below error

undefined reference to `UI_OpenSSL'


I add compile flag like below.



Reply Write