Openssl as a shared library in Android Native Code

I just compiled OpenSSL for Android. I have libcrypto.so and libssl.so libraries. I created a sample Android application called TrialApp. The idea is to use some native functions that will call the libssl and libcrypto libraries. So in my jni directory, I have TrialApp.cpp that includes a simple SHA1 example. Here is the tree structure of my Eclipse NDK application directory:

TrialApp
|
|-->Activity.java
|
|-->TrialApp.java(which includes System.LoadLibrary calls)
|
|-->jni
    |-->TrialApp.cpp
    |
    |-->Android.mk
    |
    |-->includes
    |   |
    |   |-->openssl (dir containing *.h files)
    |
    |-->precompiled
       |-->libssl.so
       |-->libcrypto.so

Here is the Android.mk file

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := TrialApp
LOCAL_SRC_FILES := TrialApp.cpp
LOCAL_EXPORT_C_INCLUDE_DIRS  := $(LOCAL_PATH)/includes/openssl
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libssl.so
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libcrypto.so
LOCAL_STATIC_LIBRARIES := sslx cryptox

include $(BUILD_SHARED_LIBRARY)

But then the openssl headers in TrialApp, .cpp cannot be found by the compiler.

The error I get: fatal error: openssl / evp.h: no such file or directory

Can someone tell me how to solve it? Thank.

+3
1

dirs -I: , LOCAL_CFLAGS : LOCAL_CFLAGS += $(cf_includes) cf_includes cf_includes:= includes/openssl + cf_includes := $(addprefix -Ijni/,$(cf_includes))
, LOCAL_CFLAGS :
LOCAL_CFLAGS += -Ijni/includes/openssl

android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

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

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

export_c_includes := $(c_includes)

LOCAL_MODULE    := TrialApp
LOCAL_SRC_FILES := TrialApp.cpp
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
LOCAL_STATIC_LIBRARIES := sslx cryptox

include $(BUILD_SHARED_LIBRARY)


,

+2

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


All Articles