How to add curl in android

Source: Internet
Author: User

Curl is a well-known software for implementing open source file transfer protocols, including HTTP, HTTPS, FTP, and other commonly used and uncommon protocols. In the official source code of the latest curl version, the android compilation file (Android. mk) is included. However, some work is required to compile the file.

The curl version I use is 7.20.0, And the android source code version is eclair 2.1.
First, extract the curl to the external directory and change the directory name to curl. (You can do this without changing the version number. However, android does not use the version number. It is a good practice ).

(1) first create a header file curl_config.h.The creation method is described in the comment in the header of the curl/Android. mk file. Run configure according to this description. The command line I used is as follows (I compiled it into the x86 version, but our purpose is to generate the curl_config.h file, so the x86 or arm is actually the same ):

Copy codeThe Code is as follows: ANDROID_ROOT = 'realpath .. /.. '& PATH = "$ ANDROID_ROOT/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/bin: $ PATH ". /configure -- host = x86-linux CC = i686-unknown-linux-gnu-gcc CPPFLAGS = "-I $ ANDROID_ROOT/external/curl/include/-I $ ANDROID_ROOT/external/curl-I $ ANDROID_ROOT/out/target/ product/eeepc/obj/STATIC_LIBRARIES/libcurl_intermediates-I $ ANDROID_ROOT/system/core/include-I $ ANDROID_ROOT/hardware/libhardware/include-I $ ANDROID_ROOT/hardware/modules/include- I $ ANDROID_ROOT/hardware/ril/include-I $ ANDROID_ROOT/dalvik/libnativehelper/include-I $ ANDROID_ROOT/frameworks/base/opengl/ include-I $ ANDROID_ROOT/external/skia/include-I $ ANDROID_ROOT/out/target/product/eeepc/obj/include-I $ ANDROID_ROOT/bionic/libc/arch-x86/include- I $ ANDROID_ROOT/bionic/libc/include-I $ ANDROID_ROOT/bionic/libstdc ++/include-I $ ANDROID_ROOT/bionic/libc/kernel/common-I $ ANDROID_ROOT/bionic/ libc/kernel/arch-x86-I $ ANDROID_ROOT/bionic/libm/include/i387-I $ ANDROID_ROOT/bionic/libthread_db/include-I $ ANDROID_ROOT/external/openssl/include "CFLAGS ="-fno-exceptions-Wno-multichar-march = i686-m32-fPIC-include $ ANDROID_ROOT/system/core/include/arch/ A target_linux-x86/AndroidConfig. h-m32-DANDROID-fmessage-length = 0-fno-strict-aliasing-Wno-unused-Winit-self-Wpointer-arith-Werror = return-type-Werror = non- virtual-dtor-Werror = address-Werror = sequence-point-Wpointer-arith-Wwrite-strings-Wunused-Winline-Wnested-externs-Wmissing-declarations-Wmissing-prototypes-Wno- long-Wfloat-equal-Wno-multichar-Wsign-compare-Wno-format-nonliteral-Wendif-labels-Wstrict-prototypes-Wdeclaration-after-statement-Wno-system- headers "LIB =" $ ANDROID_ROOT/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/lib/gcc/i686-unknown-linux-gnu/4.2.1/libgcc. a $ ANDROID_ROOT/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/lib/gcc/i686-unknown-linux-gnu/4.2.1/crtbegin. o $ ANDROID_ROOT/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/lib/gcc/i686-unknown-linux-gnu/4.2.1/crtend. o"

(2) configure cannot find openssl, so the generated configuration file does not use openssl.To use ssl, you must manually modify lib/curl_config.h and src/curl_config.h, open the macro definition HAVE_LIBSSL, secure, secure, HAVE_OPENSSL_PEM_H, secure, secure, HAVE_OPENSSL_SSL_H, secure, USE_OPENSSL, USE_SSLEAY (but note that android does not compile the engine in openssl, so do not open the macro definition ), comment out the macro definitions HAVE_MALLOC_H and HAVE_IOCTL. These two macro definitions are defined in Android_config.h. If they are not commented out, there will be many warnings during the compilation process (but they can be correctly compiled)

(3) modify the curl/Android. mk file, add external/openssl/include to the value of LOCAL_C_INCLUDES, and add libssl libz libcrypto to the value of LOCAL_SYSTEM_SHARED_LIBRARIES.

Now we can compile:
Make curl ONE_SHOT_MAKEFILE = external/curl/Android. mk TARGET_PRODUCT = <...>

However, the above Android. mk file will compile libcurl into a static library. To compile it into a dynamic library, you need to modify the Android. mk file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.