Co-Gia
Co-Gia

Reputation: 103

Error no such file or directory when build openssl in ndk

I'm working on a Android project which using AES encryption to encrypt and decrypt files. But the built-in Cipher in Java is really slow. After doing some research, I decided to use NDK to build a wrapper for aes in OpenSSL library. So I created an Android project:

Android project structure:

src
res
jni
    openssl-1.0.1e (openssl source code folder)
    Android.mk

    wrapper-folder
        aes_wrapper.c
        Android.mk
        Application.mk

First my aes_wrapper.c has a function very simple and ndk-build successfully. But when I tried to write encrypt function I include "../openssl-1.0.1e/crypto/aes/aes.h" to aes_wrapper.c, I got the error below:

openssl/opensslconf.h no such file or directory

The header file opensslconf.h is located in ../openssl-1.0.1e/include/openssl

Can anyone show me how to figure it out? Thanks a ton and sorry about my poor English.

EDIT: Here are Android.mk

  1. In folder openssl-1.0.1e/crypto/aes

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    LOCAL_MODULE := libaes
    
    LOCAL_SRC_FILES := aes_cbc.c aes_cfb.c aes_core.c aes_ctr.c aes_ebc.c aes_ige.c         aes_misc.c aes_ofb.c aes_wrap.c aes_x86core.c
    
    include $(BUILD_STATIC_LIBRARY)
    
  2. In folder wrapper

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    LOCAL_MODULE    := aes_wrapper
    LOCAL_SRC_FILES := aes_wrapper.c
    LOCAL_LDLIBS    := -lz -ljnigraphics
    
    LOCAL_STATIC_LIBRARIES += libaes
    
    LOCAL_IS_SUPPORT_LOG := true
    ifeq ($(LOCAL_IS_SUPPORT_LOG),true)
    LOCAL_LDLIBS += -llog
    endif
    
    include $(BUILD_SHARED_LIBRARY)
    

Upvotes: 2

Views: 3211

Answers (1)

eozgonul
eozgonul

Reputation: 810

You should include the header files in your Android.mk under the appropriate module as follows:

LOCAL_C_INCLUDES := /path/to/openssl-1.0.1e  

In this case, I think jni/openssl-1.0.1e should suffice. The final appearance of the module should look like:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := aes_wrapper 
LOCAL_SRC_FILES := aes_wrapper.c 
LOCAL_LDLIBS := -lz -ljnigraphics
LOCAL_C_INCLUDES := jni/openssl-1.0.1e 
LOCAL_STATIC_LIBRARIES += libaes

LOCAL_IS_SUPPORT_LOG := true 
ifeq ($(LOCAL_IS_SUPPORT_LOG),true) 
  LOCAL_LDLIBS += -llog endif

include $(BUILD_SHARED_LIBRARY)

Upvotes: 1

Related Questions