How to install openssl.so and libssl.so in an android project?

I am currently facing a build problem using openssl.

First, I built libssl.soand libcrypto.soshared librairies with ndk-build project for a guardian.

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

1) Create a jni folder

2) In this new folder, I created the include folder and copied the openssl subfolder (from the openssl package) containing the header files

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

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) Then I wrote the source file called security.c and containing the openssl initialization function

/* 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) ndk-build, libsecurity.so

, , :

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

- mk?

+2
1

, PREBUILT_SHARED_LIBRARY.

Android.mk :

# 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)

LOCAL_MODULE := security :

LOCAL_MODULE := security
...
LOCAL_SHARED_LIBRARIES= ssl crypto

LOCAL_SHARED_LIBRARIES :

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

, Android.mk .

+3

Source: https://habr.com/ru/post/1532646/


All Articles