curl-library
Re: prebuilt libcurl static library for android NDK
Date: Wed, 27 Feb 2013 14:33:27 +0000
Dear Guenter,
Having just been through the process of building for Android I can
happily say the Install.html document was of little useful value
without much hunting around the internet, downloading all of android,
mucking about with various things and eventually writing a 20 line
shell script to set all the various aspects of the system up (this was
for an SSL build). Most of this blame lies at the door of Android's
SDK (that has a habit of changing between releases - now on 4.6 or 4.7
tools), though actually once it was clear what all the bits were for
it started to go faster. Currently the help is vague, and you must
*really* understand the gubbins of the NDK to have a fighting chance.
This is fine - I know the RTFM line as well as the next - but
ultimately a waste of most people's time. It would be good if someone
put a script like mine in the build folder - one that actually works.
The script below builds a valid static libcurl, that can then be bound
into my project, however for reasons unknown to me it throws various
exceptions. I'm concerned I've managed to get the various architecture
flags right, since I get an exception on CPU detect during the global
init.
The below script builds a library on the Mac that mostly works for
Android 14. I built it by downloading the latest libcurl and openssl
into a new /{NDK}/external/libcurl and /{NDK}/external/openssl . I
then took the 3 .a files and added them to my project. Because libcurl
was the only thing referencing libssl and libcrypto, and I was
building a .so, I found the linker wouldn't build the .a file (lots of
missing functions from said libraries). Therefore I added a function
to ensure the linker had included libssl and libcyrpt like this:
// THIS FUNCTION FORCES ANDROID TO INCLUDE SSL and Crypto, it is never called!
void initStuff()
{
// Call something from libcrypto
X509 x;
X509_set_version(&x,1);
X509_certificate_type(&x,NULL);
// Call something from libssl
const SSL_METHOD *sslmethod = SSLv2_client_method();
ERR_load_crypto_strings();
//SSL_CTX_set_srp_username("");
}
This process has given me an HTTPS aware libcurl. However it seems
unreliable to me, as I'm getting the occasional crash trace like this:
#0 0x6977bf32 in Curl_raw_nequal () from
/Users/alexp700/Dev/TimingApp2013/Android/project/obj/local/armeabi/libcommonc.so
#1 0x6977f51c in Curl_checkheaders () from
/Users/alexp700/Dev/TimingApp2013/Android/project/obj/local/armeabi/libcommonc.so
#2 0x69780418 in Curl_http () from
/Users/alexp700/Dev/TimingApp2013/Android/project/obj/local/armeabi/libcommonc.so
#3 0x697876e8 in Curl_do () from
/Users/alexp700/Dev/TimingApp2013/Android/project/obj/local/armeabi/libcommonc.so
#4 0x697796f2 in multi_runsingle () from
/Users/alexp700/Dev/TimingApp2013/Android/project/obj/local/armeabi/libcommonc.so
#5 0x69779d70 in curl_multi_perform () from
/Users/alexp700/Dev/TimingApp2013/Android/project/obj/local/armeabi/libcommonc.so
#6 0x69776a4c in curl_easy_perform () from
/Users/alexp700/Dev/TimingApp2013/Android/project/obj/local/armeabi/libcommonc.so
I can see from this group you are helpful to many developers asking
the same mundane question - how do I build for Android (or where is
the libcurl.a I can use). It really would be good to just fix this
build problem so we don't have to keep asking silly questions!
The script I used to built my slightly borked library is below:
#!/bin/sh
export NDKROOT=/Users/{USER}/andk
export SYSROOT=$NDKROOT/platforms/android-14/arch-arm
export PKG_CONFIG_DIR=
export PKG_CONFIG_LIBDIR=${SYSROOT}/usr/local/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=${SYSROOT}
#exec pkg-config "$@"
export PATH="$NDKROOT/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin:$PATH"
make clean
export LDFLAGS="-L$NDKROOT/platforms/android-14/arch-arm/usr/lib
-L$NDKROOT/external/openssl/openssl-1.0.1e --sysroot=$SYSROOT -t -v"
export LIBS="-lssl -lcrypto -llog"
export CPPFLAGS="-I$NDKROOT/platforms/android-14/arch-arm/usr/include
-D__ARM_ARCH_5TE__ -DANDROID -DOS_ANDROID -D__NEW__
-D__SGI_STL_INTERNAL_PAIR_H
-I$NDKROOT/external/openssl/openssl-1.0.1e/include "
cd ../openssl/openssl-1.0.1e/
make clean
make depend
export CFLAGS="-march=armv5te -mtune=xscale -msoft-float -mandroid
-fPIC -mthumb-interwork -mthumb -mlong-calls -ffunction-sections
-fstack-protector -fno-short-enums -fomit-frame-pointer
-fno-strict-aliasing -finline-limit=64 "
./configure --host=arm-linux-androideabi --disable-shared --with-ssl
--without-libssh2 --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
make all -j16
I think the runes I have cast (possibly the CFLAGS?) are wrong. But
libcurl is a complex library to get working due to its dependencies,
and can quickly cause hair pulling.
I hope the build script is useful to someone though...
Best regards,
Alex
On 27 February 2013 11:59, Guenter <lists_at_gknw.net> wrote:
> Am 27.02.2013 12:31, schrieb Alexey Petruchik:
>
>> Maybe you have newbie friendly how to build it with ndk-build? I really
>> need libcurl on Android asap.
>
> see the docs/INSTALL file in the source tree or here online:
> http://curl.haxx.se/docs/install.html
> seach for "Android" ...
>
>
> Gün.
>
>
>
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
-- Alex Powell Tel: +44 (0) 1865 876562 Mob: +44 (0) 759 5048178 skype: alexp700 ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.htmlReceived on 2013-02-27