OpenSSL的为Android原生code共享库 [英] openssl as shared library in Android Native Code
问题描述
我刚刚编译OpenSSL的为Android。我有libcrypto.so和libssl.so共享库。我创建了一个名为TrialApp样本Android应用程序。这个想法是使用将调用的libssl和libcrypto共享库,一些本地的功能。因此,我的JNI目录下,我有一个TrialApp.cpp其中包括一个简单的SHA1 example.Here是我的NDK应用程序目录的基于Eclipse的树形结构:
I have just compiled the OpenSSL for Android. I have the libcrypto.so and libssl.so shared libraries. I created a sample Android Application called TrialApp. The idea is to use some native functions that would call the libssl and libcrypto shared libraries. Therefore, under my jni directory,I have a TrialApp.cpp which includes a simple SHA1 example.Here is the tree structure of my NDK Application directory on Eclipse:
TrialApp
|
|-->Activity.java
|
|-->TrialApp.java(which includes System.LoadLibrary calls)
|
|-->jni
|-->TrialApp.cpp
|
|-->Android.mk
|
|-->includes
| |
| |-->openssl (dir containing *.h files)
|
|-->precompiled
|-->libssl.so
|-->libcrypto.so
下面是Android.mk文件
Here is the Android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := TrialApp
LOCAL_SRC_FILES := TrialApp.cpp
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/includes/openssl
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libssl.so
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libcrypto.so
LOCAL_STATIC_LIBRARIES := sslx cryptox
include $(BUILD_SHARED_LIBRARY)
但随后在TrialApp OpenSSL的标头,的.cpp不能由编译器发现。
But then the openssl headers in TrialApp,.cpp cannot be found by the compiler.
错误我得到:
致命错误:OpenSSL的/ evp.h:没有这样的文件或目录
The error I get: fatal error: openssl/evp.h: No such file or directory
谁能告诉我如何解决呢?
谢谢你。
Can someone tell me how to resolve it? Thanks.
推荐答案
include目录都设置在编译器标志-I:用适当的密钥,因此,建立 LOCAL_CFLAGS
变量和头的位置是这样的: LOCAL_CFLAGS + = $(cf_includes)
,其中 cf_includes
的定义如下 cf_includes:=包含/ OpenSSL的
+ cf_includes:= $(添加preFIX -Ijni / $(cf_includes))
结果
换句话说,你要玷污这样LOCAL_CFLAGS:结果 LOCAL_CFLAGS + = -Ijni /包括/ OpenSSL的
Include dirs are set up in compiler flag -I: so, set up LOCAL_CFLAGS
variable with appropriate key and header location like this: LOCAL_CFLAGS += $(cf_includes)
where cf_includes
is defined like cf_includes:= includes/openssl
+ cf_includes := $(addprefix -Ijni/,$(cf_includes))
In other words you have to defile LOCAL_CFLAGS like this:LOCAL_CFLAGS += -Ijni/includes/openssl
试着用替换您android.mk
Try to replace your android.mk with
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
c_includes := $(LOCAL_PATH)
cf_includes:= includes/openssl
cf_includes := $(addprefix -Ijni/,$(cf_includes))
export_c_includes := $(c_includes)
LOCAL_MODULE := TrialApp
LOCAL_SRC_FILES := TrialApp.cpp
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
LOCAL_STATIC_LIBRARIES := sslx cryptox
include $(BUILD_SHARED_LIBRARY)
结果希望它能帮助
Hope it helps
这篇关于OpenSSL的为Android原生code共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!