如何安装openssl.so和libssl.so在Android项目? [英] How to install openssl.so and libssl.so in an android project?
问题描述
我目前面临的一个问题,构建与OpenSSL的。
I'm currently facing a build issue with openssl.
我先建 libssl.so
和 libcrypto.so
共享librairies与NDK-建立guardianproject。
I first built libssl.so
and libcrypto.so
shared librairies with ndk-build the guardianproject.
第二步,我做这个topic:
1)创建一个文件夹JNI
1)Create a jni folder
2)在这个新的文件夹我创建了一个包含文件夹,包含头文件复制粘贴OpenSSL的文件夹(从OpenSSL包)
2) In this new folder I created an includes folder and copy pasted the openssl folder (from the openssl package) containing the header files
3)创建,我复制了一个libssl.so precompiled文件夹和文件libcrypto.so
3)Create a precompiled folder where I copied the libssl.so and libcrypto.so files
4)创建一个Android.mk文件:
4)Create an Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
c_includes := $(LOCAL_PATH)
cf_includes := include/openssl
cf_includes := $(addprefix -Ijni/,$(cf_includes))
export_c_includes := $(c_includes)
LOCAL_MODULE := security
LOCAL_SRC_FILES := security.c
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
include $(BUILD_SHARED_LIBRARY)
5)我然后写所谓security.c和包含函数初始化OpenSSL的源文件
5) I then wrote a source file called security.c and containing a function initializing openssl
/* OpenSSL headers */
#include "openssl/bio.h"
#include "openssl/ssl.h"
#include "openssl/err.h"
/* Initializing OpenSSL */
void init_openssl(void){
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
}
5)建立与NDK的构建整个事情得到一个libsecurity.so文件
5) Build the whole thing with ndk-build to get a libsecurity.so file
但在这一步,似乎编译器未找到的头文件和我得到这个错误:
But at this step, it seems that the compiler doesn't find the header files and I get this error:
fatal error: openssl/bio.h: No such file or directory
我错过了MK文件的东西吗?
Did I miss something in the mk file?
推荐答案
您需要做的就是使用 preBUILT_SHARED_LIBRARY
指令。
What you need to do is use the PREBUILT_SHARED_LIBRARY
directive.
在你的Android.mk,添加以下内容:
In your Android.mk, add the following sections:
# Prebuilt libssl
include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := precompiled/libssl.so
include $(PREBUILT_SHARED_LIBRARY)
# Prebuilt libcrypto
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := precompiled/libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)
由于部分 LOCAL_MODULE:=安全
部分,添加以下内容:
LOCAL_MODULE := security
...
LOCAL_SHARED_LIBRARIES= ssl crypto
本 LOCAL_SHARED_LIBRARIES
线将替换以下行:
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libssl.so
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libcrypto.so
请看看问题<一href=\"http://stackoverflow.com/questions/10212869/calling-inner-android-mk-file-to-build-$p$pbuilt-libraries-not-working\">Calling内Android.mk文件构建prebuilt库工作不了解更多详情。
Please take a look at the question Calling inner Android.mk file to build prebuilt libraries not working for more details.
这篇关于如何安装openssl.so和libssl.so在Android项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!