27

I would like to use cURL library in my android application in native code (using NDK r5b, the latest). After researching online, it seems the only way to use cURL in android is to build the entire android source tree with curl in it, and somehow this generates a necessary config file for cURL to work on Android. I don't have any experience building the android sources from scratch and was wondering if there is a way to use cURL library in Android without having to rebuild android from source. Ideally, being able to just use cURL as a static or shared library would be perfect. I tried following the steps mentioned here...

http://curl.haxx.se/mail/lib-2009-12/0071.html

but end up getting errors in the file curlrules.h like CURL_SIZEOF_LONG definition is missing!

I assume these errors are due to not having that config file I mentioned but the steps in the above link didn't mention any of that and reported success. Any ideas?

Nitrex88
  • 2,158
  • 2
  • 21
  • 23
  • 7
    Does it have to be cURL? Android comes with an HTTP client, you know. Also, shipping a custom build of Android along with your app probably won't fly with most customers. – Seva Alekseyev Feb 10 '11 at 01:13
  • 1
    It has to be something I can use in native code, so androids HTTP client won't help. For what needs to be done it would not be good jumping back and forth between java and C. And I didn't mean to convey this would require a custom build...it wouldn't require that. I was just saying that tutorials online about using cURL in android involve creating a curl config file by building the android sources with the curl library in it (or something like that). – Nitrex88 Feb 10 '11 at 02:48
  • Hi could you solve this issue? I also have the same problem posted [here](http://stackoverflow.com/questions/13493232/android-ndk-refer-to-external-libraries-in-jni).... – AndroidDev Nov 22 '12 at 09:34

7 Answers7

19

I'm on a similar quest! I'm working on an app right now that requires cURL and just tonight in my search I came across your post here, and what I believe to be the answer:

http://thesoftwarerogue.blogspot.com/2010/05/porting-of-libcurl-to-android-os-using.html

Unlike the link you referenced, there are several follow-up comments from other people who claim to have success also following the instructions. If you manage to get it compiled before me, and wouldn't mind sending me the library, post a follow up here! (I'm pretty new to stack overflow so I don't know if you can pm.) Hope this works out for both of us!

  • I've also found this: http://code.google.com/p/android-nixutils/downloads/list but am unsure if it's what I think it is. Have not tested at all. –  Feb 24 '11 at 12:36
  • Once I realized that not only would I need cURL but also OpenSSL for my code (and I figured if I couldn't get one to compile I couldn't get them both to compile together), I gave up and decided to use the android HTTP classes to make POST and GET calls. I then just call these java methods from native code using JNI. These methods return a jobject to the native code and then I can grab the fields of the returned object (which I initialize and populate the networking result data in java) using JNI as well. Good luck if you take a similar approach or continue your search! – Nitrex88 Feb 25 '11 at 05:21
  • I'm working on getting curl built with openssl support, it looks like the configure script of curl is totally borken in this respect. My current approach is hacking a makefile on my own. Let me know if you are still interested. – anselm Apr 27 '11 at 15:26
15

It seems that there are projects on github that automated both openssl and libcurl for NDK build:

https://github.com/jahrome/curl-android

https://github.com/guardianproject/openssl-android

Going to use those in my own app, so I can have single library to deal with backend communication for both iOS and Android...

p_l
  • 1,179
  • 8
  • 17
  • There is another project on GitHub that supports porting of lib curl to BOTH iOS and Android, which includes openSSL support as well. Link: https://github.com/gcesarmza/curl-android-ios – us_david Apr 06 '16 at 17:45
14

After check all possibles post about this, I finally got a good compilation using a Linux x64 machine and Curl version 7.37.0 at path ${android-ndk-r10}.

Maybe this steps can help you:

${android-ndk-r10}/build/tools/make-standalone-toolchain.sh --platform=android-15 --arch=armv7-a --toolchain=arm-linux-androideabi-4.8 --install-dir=./tmp/android-15

export CC="${android-ndk-r10}/external/curl/tmp/android-15/bin/arm-linux-androideabi-gcc"

./configure --host=arm-linux --enable-cross-compile --enable-threaded-resolver --disable-shared --disable-ftp --disable-file --disable-ldap --disable-ldaps --disable-rtsp --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smtp --disable-gopher --disable-manual --enable-proxy --enable-ipv6 --enable-cookies --enable-symbol-hiding --disable-versioned-symbols --disable-soname-bump --disable-sspi --disable-ntlm-wb --prefix=${android-ndk-r10}/external/curl/build/curl-7.37.0

make -j4

make install

You will get a build version at ${android-ndk-r10}/external/curl/build/curl-7.37.0.

If you are using a 64bits machine to compile, maybe 2 defines are bad, and you get this error:

error: size of array '__curl_rule_01__' is negative

I solve redefining the variables in file ${CurlbuildAndroid}/include/curl/curlbuild.h (Its dangerous to do this, but it worked!):

CURL_SIZEOF_LONG 4
CURL_TYPEOF_CURL_OFF_T 4
vgonisanz
  • 11,831
  • 13
  • 78
  • 130
2

I followid this link. And it works for me. I did not have to download the whole android repository in order to compile the libcurl

MOHAMED
  • 41,599
  • 58
  • 163
  • 268
2

You can choose to download cURL for android at https://play.google.com/store/apps/details?id=io.github.faywong.curl

faywong
  • 141
  • 1
  • 5
1

I had a similar question which didn't get answered and thus was automatically removed :(

Anyway I've successfully used curl on android and have uploaded a compiled version to help the people still searching.

Download: libcurl_for_arm

I also required a typecheck-gcc.h file which I've amended and uploaded here too

Download: typecheck-gcc.h

RJButler
  • 99
  • 1
  • 9
1

"CURL_SIZEOF_LONG definition is missing!"

there is a way for it .

change the curlbuild.h at line number 162 add like this,if you are arm32 platform.

//----------------------------------------------add
#    define CURL_SIZEOF_LONG           4
#    define CURL_TYPEOF_CURL_OFF_T     long long
#    define CURL_FORMAT_CURL_OFF_T     "lld"
#    define CURL_FORMAT_CURL_OFF_TU    "llu"
#    define CURL_FORMAT_OFF_T          "%lld"
#    define CURL_SIZEOF_CURL_OFF_T     8
#    define CURL_SUFFIX_CURL_OFF_T     LL
#    define CURL_SUFFIX_CURL_OFF_TU    ULL
#  define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int
#  define CURL_SIZEOF_CURL_SOCKLEN_T 4
//#define __SYMBIAN32__