我想使用openssl的RSA,所以我需要用ndk.I將Android與openssl集成。我在https://github.com/aluvalasuman/OpenSSL1.0.1cForAndroid處下載Android的openssl的源代碼。 ndk-build
在源文件夾中生成libcrypto.so
和libssl.so
,我將其複製到$(MY_PROJECT)/ JNI/LIB /,然後鏈接它們Android.mk
那樣:如何將openssl集成到Android?
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_LIBS := $(LOCAL_PATH)/lib
LOCAL_STATIC_LIBRARIES := libcrypto libssl
LOCAL_LDLIBS := -llog
LOCAL_MODULE := jni
LOCAL_SRC_FILES := jni.c
include $(BUILD_SHARED_LIBRARY)
而測試一樣,在OpenSSL:
#include <stdio.h>
#include <string.h>
#include <openssl/rsa.h>
#define nr_bits 2048
int test_openssl()
{
RSA *rsa = RSA_generate_key(nr_bits, 65537, NULL, NULL);
return 0;
}
當我編譯它,把它扔到了錯誤:
....jni/license/license.c:10: error: undefined reference to 'RSA_generate_key'
collect2: ld returned 1 exit status
有誰知道WH問題在哪?如果有人能幫忙,我將非常感激。