2

I'm currently facing a build issue with openssl.

I first built libssl.so and libcrypto.so shared librairies with ndk-build the guardianproject.

As a second step, I integrated the libs with my android project by doing the following as explained in this topic:

1)Create a jni folder

2) In this new folder I created an includes folder and copy pasted the openssl folder (from the openssl package) containing the header files

3)Create a precompiled folder where I copied the libssl.so and libcrypto.so files

4)Create an Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

c_includes := $(LOCAL_PATH)
cf_includes := include/openssl

cf_includes := $(addprefix -Ijni/,$(cf_includes))

export_c_includes := $(c_includes)

LOCAL_MODULE := security
LOCAL_SRC_FILES := security.c
LOCAL_CFLAGS += $(cf_includes)
LOCAL_EXPORT_C_INCLUDES := $(export_c_includes)
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libssl.so
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libcrypto.so

include $(BUILD_SHARED_LIBRARY)

5) I then wrote a source file called security.c and containing a function initializing openssl

/* OpenSSL headers */

#include "openssl/bio.h"
#include "openssl/ssl.h"
#include "openssl/err.h"

/* Initializing OpenSSL */

void init_openssl(void){
    SSL_load_error_strings();
    ERR_load_BIO_strings();
    OpenSSL_add_all_algorithms();
}

5) Build the whole thing with ndk-build to get a libsecurity.so file

But at this step, it seems that the compiler doesn't find the header files and I get this error:

fatal error: openssl/bio.h: No such file or directory

Did I miss something in the mk file?

Community
  • 1
  • 1
onizukaek
  • 1,082
  • 1
  • 14
  • 38

1 Answers1

4

What you need to do is use the PREBUILT_SHARED_LIBRARY directive.

In your Android.mk, add the following sections:

# Prebuilt libssl
include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := precompiled/libssl.so
include $(PREBUILT_SHARED_LIBRARY)

# Prebuilt libcrypto
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := precompiled/libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)

As part the LOCAL_MODULE := security section, add the following:

LOCAL_MODULE := security
...
LOCAL_SHARED_LIBRARIES= ssl crypto

This LOCAL_SHARED_LIBRARIES line will replace the following lines:

LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libssl.so
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libcrypto.so

Please take a look at the question Calling inner Android.mk file to build prebuilt libraries not working for more details.

Community
  • 1
  • 1
Samveen
  • 3,482
  • 35
  • 52
  • Thanks, I managed to find this solution too, and I worked with a .cpp file (because of eclipse... :) ). – onizukaek Aug 20 '13 at 13:46