I am trying to write a wrapper for encryption/decryption file for Android using OpenSSL open source library. So I created a NDK Android project to compile library OpenSSL using NDK.
Here is project structure:
Android Project
src
jni
openssl-1.0.1e (folder contains openssl source code)
crypto (folder contains crypto source code)
Android.mk (the Android makefile to define STATIC_LIBRARY)
include
openssl (folder contains header files)
wrapper (folder contains wrapper source code, my implementation here)
aes_wrapper.c (my wrapper implementation)
Android.mk (the Android makefile to define SHARED_LIBRARY)
Android.mk (the Android makefile that calls all sub android makefiles)
Application.mk (the Application makefile, I use to define APP_ABI)
Here is content of Android.mk in folder jni/openssl-1.0.1e/crypto
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := \
$(NDK_PROJECT_PATH) \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/asn1 \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/aes \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/evp \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/include \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/include/openssl
LOCAL_SRC_FILES := all source files here
LOCAL_MODULE := crypto
include $(BUILD_STATIC_LIBRARY)
Here is content of Android.mk in folder jni/wrapper
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := \
$(NDK_PROJECT_PATH) \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/asn1 \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/aes \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/crypto/evp \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/include \
$(NDK_PROJECT_PATH)/jni/openssl-1.0.1e/include/openssl
LOCAL_SRC_FILES := aes_wrapper.c
LOCAL_STATIC_LIBRARIES += crypto
LOCAL_MODULE := aes_wrapper
include $(BUILD_SHARED_LIBRARY)
Here is content of Android.mk in folder jni
include $(call all-subdir-makefiles)
Here is content of Application.mk in folder jni
APP_ABI := all
When I call ndk-build I got some "undefined reference to" errors. I have been trying to fix a couple of days but unfortunately I was not successful. Could anyone help me? Any help will be appreciated.
EDIT: I got bunch of errors like this
/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:
./obj/local/armeabi-v7a/objs/aes_wrapper/aes_wrapper.o: in function encrypt:jni/wrapper/aes_wrapper.c:21: error: undefined reference to 'AES_encrypt'
AES_encryptand friends. You should be usingEVP_*functions. See EVP Symmetric Encryption and Decryption on the OpenSSL wiki. In fact, you should probably be using authenticated encryption because it provides both confidentiality and authenticity. See EVP Authenticated Encryption and Decryption on the OpenSSL wiki. - jww