Skip to content
Compile openssl and curl for Android
Shell
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
curl @ 2cfac30
openssl @ 894da2f
.gitignore
.gitmodules
LICENSE
README.md
build-curl.sh
build-openssl.sh
build.sh
my-build.sh

README.md

openssl-curl-android

Compile openssl and curl for Android

Prerequisites

Make sure you have Android NDK installed.

You may also need to install autoconf and libtool toolchains.

Download

If you do not want to compile them yourself, you can download pre-compiled static libraries from releases. They are in build.tar.gz.

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.

Usage

git clone https://github.com/robertying/openssl-curl-android.git
git submodule update --init --recursive

export ANDROID_NDK_HOME=your_android_ndk_root_here # e.g. $HOME/Library/Android/sdk/ndk/21.0.6113669
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=21 # or any version you want

chmod +x ./build.sh
./build.sh

All compiled libs are located in build/openssl and build/curl directory.

Use NDK to link those libs, part of Android.mk example:

include $(CLEAR_VARS)
LOCAL_MODULE := curl
LOCAL_SRC_FILES := build/curl/$(TARGET_ARCH_ABI)/libcurl.a
include $(PREBUILT_STATIC_LIBRARY)

Options

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_PATH is 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.

Working Examples

  • See this minimal example which calls curl from Android app, using JNI to use libcurl: AndroidCurlExample. It includes Android.mk setup and JNI configurations.

  • Checkout this more complex repo to see how to integrate other compiled static libraries into an existing Android project, including Android.mk setup and JNI configurations.

You can’t perform that action at this time.