2

I try to build OpenSSL for arm Android as described in this answer. But when I build OpenSSL with "shared" flag, it produces 4 files: libcrypto.so.1.0.0, libssl.so.1.0.0 and 2 symbolic links: libcrypto.so and libssl.so

In Android.mk file I link these libraries to project:

include $(CLEAR_VARS)
LOCAL_MODULE    := openssl-ssl
LOCAL_SRC_FILES := libs/libssl.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := openssl-crypto
LOCAL_SRC_FILES := libs/libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)

But when I try to run my application java.lang.UnsatisfiedLinkError occurs with message "Could not load library libssl.so.1.0.0..."

I tryed to delete links and rename libssl.so.1.0.0 and libcrypto.so.1.0.0 to libssl.so and libcrypto.so respectively but it doesn't help.

How can I use OpenSSL in my project?

Community
  • 1
  • 1
Lighter
  • 75
  • 2
  • 10

4 Answers4

2

To be on the safe side, use a static build of openssl. Otherwise you will probably find that the system one is loaded instead of your custom one (System.loadLibrary() looks in /system/lib first). Or go into openssl make file and change its soname to something unique.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • I need to build "own" OpenSSl version with custom engine so I can't use /system/lib/libssl.so. But your advice is very helpful. Thanks! – Lighter Jan 31 '14 at 14:36
2

What worked for me was: Edit the openssl Makefile.shared and replace

-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX

with

-soname=$$SHLIB

That way the library internal name is changed do libcrypto.so and libssl.so instead of libcrypto.so.1.0.0

Clean and recompile openssl and your app.

Giovani
  • 211
  • 1
  • 7
0

you don't need to delete the links and rename the files. Just keep them in the same folder which is referenced in the Android.mk file.(in your case, the four files should all be in the lib folder)

0

You will need to build the static version of the libraries. libcrypto.a and libssl.a It is not possible to load the custom libcrypto.so and libssl.so because the Android Zygote process has already loaded its own version of these shared libraries.

OpenSSL-1.0.2k configurations that I am currently using on Android:

ARM: ./Configure android no-shared no-hw no-dso no-krb5 no-zlib --openssldir=/home/jeff/openssl/$ANDROID_API

ARM-v7a: ./Configure android-armv7 no-shared no-hw no-dso no-krb5 no-zlib --openssldir=/home/jeff/openssl/$ANDROID_API

x86: ./Configure android-x86 no-shared no-hw no-dso no-krb5 no-zlib --openssldir=/home/jeff/openssl/$ANDROID_API

Jeff Archer
  • 79
  • 2
  • 5