⬆️ ⬇️

How to port libcURL to Android

The article is intended for developers under the Android NDK, who are going to work with the wonderful libcURL library and have at its disposal its source code for rebuilding into a static library. The author does not claim to be an absolutely correct solution to the problem of porting this library, but only shares his experience.



All interested in asking under the cat.



Preamble


I am developing my own Android application on Windows 7, using Eclipse Indigo for a Java wrapper for a native application compiled by Cygwin. The Native part is written in C ++ with the inclusion of cross-platform C libraries and with the ability to debug in Visual Studio 2010 Express.



Recently, during development, it became necessary to download images from the Internet. According to previous experience of developing for Windows, nothing better than libcURL I did not see, that's why I decided to stop there.

')

Plot


The first surprise came to light when I started downloading the source from the developer’s website: curl.haxx.se/download.htm . Under Android, only the assembled version is posted there. It does not matter, I thought - "Somehow I will build the assembly myself", I downloaded the raw materials (curl-7.27.0).



It was not late in the evening and in an hour I planned to finish this task and move on to more interesting activities. I looked through the Android.mk file fluently and put everything into my own Android.mk to build this miracle. Very unpleasant errors began to come out in cygwin - “CURL_SIZEOF_LONG definition is missing!”, And others like them. It is useful to look for a solution to the problem: stackoverflow.com/questions/4952169/using-curl-in-android . I did everything as advised, but errors with missing macros remained. As a result, I realized that it was stupid to experiment further on myself, I went to read articles of the type: thesoftwarerogue.blogspot.ru/2010/05/porting-of-libcurl-to-android-os-using.html . It was already well past midnight, I had to wrap up on such a non-positive note.



In the morning, I started to read the above article on a fresh mind and realized that the very concept of assembly is contrary to common sense. To build, you need to create curl_config.h under the full source code of Android! It was simply pointless to read further, especially since the found variants of this magic header did not allow to avoid the above errors in cygwin. Having firmly decided for myself that this path is flawed, I began to develop an abandoned idea about building just from the sources, abandoned the day before. I found an article where a friend very kindly said that you could do this and put it out ... a compiled version of blog.glowinteractive.com/2011/11/porting-curl-to-android-as-static-library . Thanks at least for the fact that at least I would suggest that you need to manually make the configuration header, which I did. I took config-mac.h, made config-android.h out of it and included it in setup.h. And about a miracle - bypassing the errors by refining config-android.h, it turned out to build a library from source and test the functionality I need (downloading images from the Internet).



Refinement Instructions:


in include / curl / curlbuild.h


we find

#elif defined(__GNUC__) 
add section

 # else # 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 
you can call her
  #elif defined(ANDROID) 
following after

 elif defined(__x86_64__) || defined(__ppc64__)... 


in lib / setup.h


we find

 #ifdef __VXWORKS__ # include "config-vxworks.h" #endif 
and add after it

 #ifdef __GNUC__ # include "config-android.h" #endif 


Create lib / config-android.h from lib / config-mac.h



in lib / config-android.h


we change

 #define OS "mac" 
on

 #define OS "android" 


we change

 #define HAVE_IOCTL_FIONBIO 1 
on

 #define HAVE_FCNTL_O_NONBLOCK 1 


we change

 #define SEND_TYPE_ARG3 size_T 
on

 #define SEND_TYPE_ARG3 size_t 


delete rows

 #define HAVE_EXTRA_STRICMP_H 1 #define HAVE_EXTRA_STRDUP_H 1 




After writing the article, I stumbled upon groups.google.com/forum/?fromgroups=# ! Topic / android-ndk / JmJYxZ7s8G8. There is the same thing as here, but again, too much needs to be thought out.

Source: https://habr.com/ru/post/158743/



All Articles