Reference article:
1.NDK Environment Configuration http://blog.csdn.net/smfwuxiao/article/details/6587709
Configuration modification of 2.libcurl http://piggyq.com/pen/compile-libcurl-and-openssl-on-android-using-ndk.html
Assume that you have compiled OpenSSL, and that the installation directory (the directory where the header files and libraries are located) is Openssl-android
First step: Configure the NDK environment (including system environment Sysroot and compiler cc)
The Android NDK provides scripts that allow you to customize a set of tool chains. For example:
$NDK/build/tools/make-standalone-toolchain.sh--platform=android-5--install-dir=/tmp/my-android-toolchain [-- Arch=x86]
The sysroot environment and Toolchain will be created in/tmp/my-android-toolchain. The--arch option selects the instruction schema for the target program, which by default is arm.
If the--INSTALL-DIR option is not added,/tmp/ndk/<toolchain-name>.tar.bz2 is created.
(Perform make-standalone-toolchain.sh--help view Help.) )
After running, use this:
$ export Path=/tmp/my-android-toolchain/bin: $PATH
$ Export CC=ARM-LINUX-ANDROIDEABI-GCC
$ Export cxx=arm-linux-androideabi-g++
$ export cxxflags= "-lstdc++"
After executing the above command to set the environment variable, you can compile it directly (for example, execute./configure and make gets the arm program).
No more setting sysroot, CC. Also, you can use STL, exception, RTTI.
Step Two: Configure Libcurl
To enter the Curl root directory and run the./configure--host=arm-linux-androideabi--with-ssl=/openssl-android
To ensure that the generated configuration file is correct, you need to confirm it manually, open lib/curl_config.h,
Open Macro definition Have_libssl, Have_openssl_crypto_h, Have_openssl_err_h, have_ Openssl_pem_h, Have_openssl_pkcs12_h,
Have_openssl_rsa_h, Have_openssl_ssl_h, Have_openssl_x509_h, USE_OPENSSL, Use_ssleay
(but note that Android does not compile the engine in OPENSSL, so do not open the macro definition Have_openssl_engine_h),
also comment out the macro definition Have_malloc_h and have_ IOCTL, these two macro definitions are defined in android_config.h, and there will be a lot of warnings in the compilation process (but can compile correctly)
Step three: Compiling Libcurl
Modify the ANDROID.MK, delete the Curl module we don't need, and add openssl-android/include and Openssl-android/crypto to the value of the local_c_includes variable.
Then modify the android.mk in the following ways. After modifying, change the directory package/android to Package/jni, use the terminal to enter the package, and then execute ndk-build.
1. Compiling the ARM version (shared library dependent on OpenSSL)
First add the dynamic library module before Libcurl, so that the libssl.so copy to the correct location, as follows.
Local_path:= $ (call My-dir)/. /..
Common_cflags: =-wpointer-arith-wwrite-strings-wunused-winline-wnested-externs-wmissing-declarations- Wmissing-prototypes-wno-long-long-wfloat-equal-wno-multichar-wsign-compare-wno-format-nonliteral-wendif-labels -wstrict-prototypes-wdeclaration-after-statement-wno-system-headers-dhave_config_h
#using libssl.so
Include $ (clear_vars)
Local_module: = Libssl
Local_src_files: =/home/administrator/openssl-android/libs/armeabi/libssl.so
Include $ (prebuilt_shared_library)
#using libcrypto.so
Include $ (clear_vars)
Local_module: = Libcrypto
Local_src_files: =/home/administrator/openssl-android/libs/armeabi/libcrypto.so
Include $ (prebuilt_shared_library)
# Build the Libcurl library
Include $ (clear_vars)
Include $ (local_path)/lib/makefile.inc
Curl_headers: = \
Curlbuild.h \
Curl.h \
CURLRULES.H \
Curlver.h \
Easy.h \
Mprintf.h \
MULTI.H \
STDCHEADERS.H \
Typecheck-gcc.h
Local_src_files: = $ (Addprefix lib/,$ (csources))
Local_c_includes + = $ (local_path)/include/\
$ (Local_path)/lib/\
$ (Local_path)/.. /openssl-android/include/\
$ (Local_path)/.. /openssl-android/crypto/
local_system_shared_libraries+= Libssl Libcrypto Libz
Local_cflags + = $ (common_cflags)
Local_copy_headers_to: = Libcurl/curl
Local_copy_headers: = $ (Addprefix include/curl/,$ (curl_headers))
local_module:= Libcurl
Local_module_tags: = Optional
All_prebuilt + = $ (local_path)/notice
$ (Local_path)/notice: $ (local_path)/copying | $ (ACP)
$ (Copy-file-to-target)
Include $ (build_static_library)
2. Compiling the ARM version (dependent on OpenSSL's static library)
Android.mk modification is similar to 3, change the static library path slightly
3. Compiling version x86 (dependent on OpenSSL static library)
Modify Android.mk
Local_path:= $ (call My-dir)/. /..
Common_cflags: =-wpointer-arith-wwrite-strings-wunused-winline-wnested-externs-wmissing-declarations- Wmissing-prototypes-wno-long-long-wfloat-equal-wno-multichar-wsign-compare-wno-format-nonliteral-wendif-labels -wstrict-prototypes-wdeclaration-after-statement-wno-system-headers-dhave_config_h
Include $ (clear_vars)
Local_module: = Libssl
Local_src_files: =/HOME/ADMINISTRATOR/OPENSSL-ANDROID/OBJ/LOCAL/X86/LIBSSL.A
Include $ (prebuilt_static_library)
Include $ (clear_vars)
Local_module: = Libcrypto
Local_src_files: =/HOME/ADMINISTRATOR/OPENSSL-ANDROID/OBJ/LOCAL/X86/LIBCRYPTO.A
Include $ (prebuilt_static_library)
#########################
# Build the Libcurl library
Include $ (clear_vars)
Include $ (local_path)/lib/makefile.inc
Curl_headers: = \
Curlbuild.h \
Curl.h \
CURLRULES.H \
Curlver.h \
Easy.h \
Mprintf.h \
MULTI.H \
STDCHEADERS.H \
Typecheck-gcc.h
Local_src_files: = $ (Addprefix lib/,$ (csources))
Local_c_includes + = $ (local_path)/include/\
$ (Local_path)/lib/\
$ (Local_path)/.. /openssl-android/include/\
$ (Local_path)/.. /openssl-android/crypto/
Local_static_libraries + = Libssl Libcrypto
Local_system_shared_libraries + = Libz
Local_cflags + = $ (common_cflags)
Local_copy_headers_to: = Libcurl/curl
Local_copy_headers: = $ (Addprefix include/curl/,$ (curl_headers))
local_module:= Libcurl
Local_module_tags: = Optional
All_prebuilt + = $ (local_path)/notice
$ (Local_path)/notice: $ (local_path)/copying | $ (ACP)
$ (Copy-file-to-target)
Include $ (build_static_library)
Add application.mk to the same directory in ANDROID.MK and add the following:
App_abi: = x86
Target_arch: = x86
UBUNTU+NDK compiling support for HTTPS Libcurl