如何在Android中使用没有头文件的共享库?

时间:2017-11-09 11:05:54

标签: android android-ndk java-native-interface ndk-build libcrypto

我有一个共享库(例如libcrypto.so),但没有头文件。

我可以在其他模块中使用这个lib吗?

我尝试使用LOCAL_EXPORT_C_INCLUDES导出头文件,但它不起作用。

这是预建模块:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto
LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libcrypto.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)

并且,这是使用libcrypto的模块:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES += test.c # include "openssl/crypto.h"
LOCAL_C_INCLUDES += $(crypto_PATH)/include
LOCAL_SHARED_LIBRARIES += libcrypto

LOCAL_MODULE := libtest
LOCAL_MODULE_TAGS := optional
LOCAL_ARM_MODE := arm
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)

这是libcrypto模块(boringssl):

LOCAL_PATH := $(call my-dir)
# Target shared library
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libcrypto
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/src/include
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/crypto-sources.mk
LOCAL_SDK_VERSION := 9
LOCAL_CFLAGS += -fvisibility=hidden -DBORINGSSL_SHARED_LIBRARY -DBORINGSSL_IMPLEMENTATION -DOPENSSL_SMALL -Wno-unused-parameter
# sha256-armv4.S does not compile with clang.
LOCAL_CLANG_ASFLAGS_arm += -no-integrated-as
LOCAL_CLANG_ASFLAGS_arm64 += -march=armv8-a+crypto
include $(LOCAL_PATH)/crypto-sources.mk
include $(BUILD_SHARED_LIBRARY)
编辑:添加了boringssl模块。我实际上在test.c中使用了#include "openssl/crypto.h"

1 个答案:

答案 0 :(得分:0)

通常,您会在 include / openssl 下找到 crypto.h 。因此,在您的情况下,要么更改 test.c

中的#include语句
#include "openssl/crypto.h"

或(少推荐),编辑

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/openssl