How to use openSSL Library in the ANDROID application
Have you tried this, its a standalone build of the openssl that's included in Android: https://github.com/fries/android-external-openssl/blob/master/README.android
There are several tips about using OpenSSL with Android:
It is necessary to build OpenSSL libraries using NDK tools, otherwise they will be incompatible with the NDK. Compiling the latest OpenSSL for Android
CC=~/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc ./Configure android-armv7 export ANDROID_DEV=~/android-ndk-r9//platforms/android-8/arch-arm/usr make build_libs
It is supposed that these commands are executed in the source directory of OpenSSL.
In order to use these libraries (ssl and crypto) with your own library from the NDK, you need to create additional *.mk files in jni folder. For example:
include $(CLEAR_VARS) LOCAL_MODULE := ssl-crypto LOCAL_SRC_FILES := openssl-crypto/libcrypto.so include $(PREBUILT_SHARED_LIBRARY)
and include them into the main Android.mk:
include $(LOCAL_PATH)/openssl-ssl/Android.mk
and probably add
include $(CLEAR_VARS)
after it to avoid errors. Libraries will be placed into
libs/armabi
and.apk
.If you will encounter with
could not load library ... needed by ...
error then it probably means that your library has soname with a version number. AFAIK NDK is unable to work with such libraries at this moment. There is a workaround (Dalvik is looking for .so file with '.0' extension - why?):rpl -R -e library.so.1.1 "library.so\x00\x00\x00\x00" libs obj
where
rpl
is a linux string replacement tool. Run this script after building and before running your application and it will remove version number from the project files. Follow the link for more information.If you use a C++ compiler you may get "undefined references" error in your C functions. Use
extern "C" {}
to avoid this (see "C++ name mangling" for more info).At last make sure that there is a network permission in the manifest.