Compile openssl and curl for Android
Make sure you have
Android NDK installed.
You may also need to install
libtool toolchains as well as build essentials.
If you do not want to compile them yourself, you can download pre-compiled static libraries from releases. They are in
Doing your own compilation is recommended, since the pre-compiled binary can become outdated soon.
Checkout newer versions in git submodules to compile newer versions of the libraries. For example, to build
cd openssl git fetch git checkout OpenSSL_1_1_1l cd .. cd curl git fetch git checkout curl-7_78_0 cd ..
git clone https://github.com/robertying/openssl-curl-android.git cd openssl-curl-android git submodule update --init --recursive export NDK=your_android_ndk_root_here # e.g. $HOME/Library/Android/sdk/ndk/23.0.7599858 export HOST_TAG=see_this_table_for_info # e.g. darwin-x86_64, see https://developer.android.com/ndk/guides/other_build_systems#overview export MIN_SDK_VERSION=23 # or any version you want chmod +x ./build.sh ./build.sh
All compiled libs are located in
Use NDK to link those libs, part of
include $(CLEAR_VARS) LOCAL_MODULE := curl LOCAL_SRC_FILES := build/curl/$(TARGET_ARCH_ABI)/libcurl.a include $(PREBUILT_STATIC_LIBRARY)
Change scripts' configure arguments to meet your own needs.
For now, using TLS (https) in Android would throw
peer verification failed.
Please explicitly set
curl_easy_setopt(curl, CURLOPT_CAINFO, CA_BUNDLE_PATH);where
CA_BUNDLE_PATHis your ca bundle path in the device storage.
You can download and copy cacert.pem to Android assets or the device internal storage to get TLS working for libcurl.
See this minimal example which calls
curlfrom Android app, using
libcurl: AndroidCurlExample. It includes
Checkout this more complex repo to see how to integrate other compiled static libraries into an existing Android project, including