Compile openssl and curl for Android. This is a personal fork of robertying/openssl-curl-android.
Make sure you have Android NDK
installed.
And also necessary autoconf
and libtool
toolchains.
If you do not want to compile them yourself, you can download pre-compiled binaries and static libraries from releases. They are built by CircleCI:
git clone https://github.com/robertying/openssl-curl-android.git
git submodule update --init --recursive
export ANDROID_NDK_HOME=your_android_ndk_bundle_root_here
export HOST_TAG=see_this_table_for_info # 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)
Change scripts' configure arguments to meet your requirements.
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 in the devide storage.
You can download and copy cacert.pem to the internal storage to get tls working for libcurl.
Checkout this repo to see how to integrate compiled static libraries into an existing Android project, including Android.mk
setup and JNI
configurations.