I. GENERAL overview
Library C: Libcurl 3.7
Target platform: Android
Build platform: Ubuntu 12
Compiler tool: NDK R7 or later
Second, known methods
1. The official web site gave two methods, the first method is to use the Android source code to compile a piece, the original text is as follows:
Method using the static makefile:
See the build notes in the Packages/android/android.mk file.
Android.mk as follows:
# Google Android makefile for Curl and Libcurl
#
# This file can is used when building curl using the full Android source
# release or the NDK. Most users does not want or need to does this; Please
# instead read the Android section on Docs/install for alternate
# methods.
#
# Place the Curl source (including this makefile) into external/curl/in the
# Android source tree. Then build them "make curl" or just ' make Libcurl '
# from the Android root. Tested with Android versions 1.5, 2.1-2.3
#
# note:you must first create a curl_config.h file by running configure in the
# Android Environment. The only-I-I ' ve found to does this is tricky. Perform A
# normal Android build with Libcurl in the source tree, providing the target
# "Showcommands" to make. The build would eventually fail (because Curl_config.h
# doesn ' t exist yet), but the compiler commands used to build curl would be
# shown. Now, from the external/curl/directory, run Curl ' s normal configure
# command with flags this match what Android itself uses. This would mean
# putting the compiler directory into the PATH, putting The-i,-isystem and
#-D options into Cppflags, putting the-w,-M,-F,-O and-nostdlib options
# into CFLAGS, and putting THE-WL,-l and-l options into LIBS, along with the
# path to the files libgcc.a, CRTBEGIN_DYNAMIC.O, and CCRTEND_ANDROID.O.
# Remember that the paths must is absolute since you'll not be running
# Configure from the same directory as the Android make. The normal
# Cross-compiler options must also be set. Note that the-c,-O,-MD and
# Similar flags must not being set.
#
# to see all the LIBS options, you'll need to do the "showcommands" trick in an
# executable that's already buildable and watch what the flags Android uses to link
# It (DHCPCD is a good choice to watch). You ' ll also want to add-l options to
# LIBS that point to the Out/.../obj/lib/and out/.../obj/system/lib/
# directories So, additional libraries can be found and used by curl.
#
# The end result would be a configure command that looks something like this
# (the environment variable A is set to the Android root path which makes the
# command Shorter):
#
# a= ' Realpath. /.. ' && \
# path= "$A/prebuilt/linux-x86/toolchain/arm-eabi-x/bin: $PATH" \
#./configure--host=arm-linux CC=ARM-EABI-GCC \
# cppflags= "-I $A/system/core/include ..." \
# cflags= "-nostdlib-fno-exceptions-wno-multichar ..." \
# libs= "$A/prebuilt/linux-x86/toolchain/arm-eabi-x/lib/gcc/arm-eabi/x\
#/INTERWORK/LIBGCC.A ... "
#
# Finally, copy the file COPYING to NOTICE so, the curl license gets put
# into the right place (and see the note on this below).
3. The second method uses the Android NDK script to customize a set of tool chains for easy configuration of variables
Method using a Configure Cross-compile (tested with Android NDK r7c, R8):
Prepare the toolchain of the Android NDK for standalone use; This can is done by invoking the script:
./build/tools/make-standalone-toolchain.sh
Which creates a usual cross-compile toolchain. Lets assume that you put the this toolchain below/opt then invoke the Configure with the something like:
Export Path=/opt/arm-linux-androideabi-4.4.3/bin: $PATH
./configure--host=arm-linux-androideabi [more Configure options]
Make
Three, their own methods
The first method requires the use of Android source code, very inconvenient, the second need to configure a lot of configure parameters to ensure that make successful. My approach is to combine the above two methods, use./configure to get curl_config.h and so on, and then use Ndk-build to compile android.mk instead of using make directly.
1. Build the NDK Environment:
1.1 Downloads NDK
Official website download page: http://developer.android.com/tools/sdk/ndk/index.html after downloading, unzip
Note: Download the NDK that matches your operating system number, and download ndk32, because Android's 64-bit support is not long, most of it is 32-bit, the newer the better, the new version will fix many compiler bugs, support more language features.
1.2 Configuring NDK Environment parameters
Open ~/.BASHRC File:
Export NDK_HOME=~/ANDROID/ANDROID-NDK-R8
Export path= $PATH: $NDK _home
Export path= $PATH: $NDK _home/toolchains/arm-linux-androideabi-4.6/prebuilt/linux/bin
Test it.
Ndk-build–v
Note 1: There are three ways to modify an environment variable, but the above shutdown will not fail:
For example, to add the/etc/apache/bin directory to the path
- #PATH = $PATH:/etc/apache/bin
Using this method, each time you log out of path, you will recover
2. #vi/etc/profile
Add Path= $PATH in place:/etc/apache/bin
This method is best unless you force manually modifying the value of path, otherwise it will not be changed
3. #vi ~/.bash_profile
Modify the path line to add/etc/apache/bin
This method is for the user to work
Note 2:ndk-build is used in two ways
- CD ~/android-ndk-r9/samples/hello-jni/jni
Ndk-build
2. $NDK _home/ndk-build-c ~/android-ndk-r9/samples/hello-jni/jni
To indicate the project directory path with-C
2. Configuring and Compiling Libcurl
2.1 Download source code http://curl.haxx.se/download.html, unzip
2.2 After the command line enters the Curl directory, execute
./configure–host=arm-linux-androideabi
Note: Remember that host must be a tool chain prefix
2.3 Modify the Package/android/android.mk, remove the corresponding executable file related statements, we just build a static library on the line. Then change the package/android to Package/jni.
Note: The file structure must be jni/android.mk, otherwise ndk-build cannot be found.
2.4 Command line into the package, execute ndk-build, done.
Libcurl porting to Android