Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to build external OpenSSL library for Android NDK on Windows/Cygwin

I need to build the latest OpenSSL (1.0.0g) for an Android application. I am trying to follow the example given by https://github.com/fries/android-external-openssl, but I just can't get it built.

I am running Windows 7 Professional (64-bit) with a complete and recent Cygwin. I have installed the Android SDK and NDK, and I can successfully build and run the NDK's hello-jni sample application.

I created a new sample NDK app called hello-openssl. In its jni directory, I created an openssl directory. There, I unzipped https://github.com/fries/android-external-openssl/zipball/master, which gave me this tree structure under c:\android\android-ndk\samples\hello-openssl:

jni
+- openssl
   +- apps
   +- crypto
   +- include
      +- openssl
   +- ssl

I then modified the Android.mk file in the jni directory in an attempt to include the OpenSSL files:

subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
    openssl \
))

include $(subdirs)

Now when I execute ndk-build, it compiles several .c files, but then quickly fails:

Compile thumb  : crypto <= cryptlib.c
In file included from jni/openssl/crypto/cryptlib.c:117:
jni/openssl/crypto/cryptlib.h:65:18: error: e_os.h: No such file or directory
jni/openssl/crypto/cryptlib.h:72:28: error: openssl/crypto.h: No such file or directory

I found http://osdir.com/ml/android-ndk/2010-07/msg00424.html, which tells me to "add jni and jni/include to the above LOCAL_C_INCLUDES" in crypto/Android.mk, but I can't figure out the syntax I should use to achieve this.

I also can't figure out of I have the correct directory structure.

I sincerely appreciate any help that can be offered.

Thanks!

like image 495
Martin Del Vecchio Avatar asked Jan 30 '12 14:01

Martin Del Vecchio


1 Answers

I solved this problem by abandoning https://github.com/fries/android-external-openssl and instead using https://github.com/guardianproject/openssl-android.

It is based on a more recent OpenSSL (1.0.0a), and it builds in the NDK without any modifications.

Note that in order to use these libraries in an Android app, you must rename them. If you simply include the resulting libssl.so and libcrypto.so in your app, then call System.LoadLibrary ("crypto") and System.LoadLibrary ("ssl"), you will get the OpenSSL libraries included in the Android system, not your custom libraries.

To do this, just do a full-word search and replace ("libssl" -> "libsslx", and "libcrypto" -> "libcryptox") in each Android.mk (i.e, in /crypto, /ssl, and /apps).

Then in your Android app, call SystemLoadLibrary ("cryptox") and System.LoadLibrary ("sslx")

like image 158
Martin Del Vecchio Avatar answered Nov 15 '22 07:11

Martin Del Vecchio