我正在嘗試使用OpenSSL開放源代碼庫爲Android編寫加密/解密文件的封裝器。所以我創建了一個NDK Android項目來使用NDK編譯庫OpenSSL。通過NDK訪問OpenSSL AES_encrypt函數時出現未定義的引用錯誤
下面是項目結構:
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)
以下是文件夾Android.mk內容JNI /的OpenSSL 1.0.1e /加密
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)
以下是文件夾Android.mk的內容JNI /包裝
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)
以下是在文件夾JNI Android.mk的內容
include $(call all-subdir-makefiles)
這裏是文件夾JNI
APP_ABI := all
Application.mk的內容當我打電話NDK建造我得到了一些「未定義的引用」錯誤。我一直在努力修復幾天,但不幸的是我沒有成功。任何人都可以幫我嗎?任何幫助將不勝感激。
編輯:我得到了一堆錯誤這樣
/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_encrypt'和朋友。您應該使用'EVP_ *'功能。請參閱[EVP對稱加密和解密](https://wiki.openssl.org/index。php/EVP_Symmetric_Encryption_and_Decryption)在OpenSSL wiki上。事實上,您應該使用經過身份驗證的加密,因爲它提供了*機密性和真實性。請參閱OpenSSL wiki上的[EVP Authenticated Encryption and Decryption](https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption)。 – jww