java.lang.UnsatisfiedLinkError:dlopen失败:无法加载库" libcrypto.so.1.0.0"需要" libPrivateSsl.so&#34 ;;

时间:2018-01-30 06:22:37

标签: android c++ android-ndk openssl java-native-interface

我在我的项目中使用预建的openssl。加载应用程序崩溃并发出此错误

java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "libcrypto.so.1.0.0" needed by "libPrivateSsl.so"; caused by library "libcrypto.so.1.0.0" not found

我的android.mk看起来像这样

LOCAL_PATH := $(call my-dir)

# Prebuilt libssl
include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := precompiled/libPrivateSsl.so
include $(PREBUILT_SHARED_LIBRARY)

# Prebuilt libcrypto
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := precompiled/libPrivateCrypto.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := myLibrary
TARGET_PLATFORM := android-3
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := ssl crypto


include $(BUILD_SHARED_LIBRARY)

在像这样的活动中加载库

static {
    System.loadLibrary("PrivateSsl");
    System.loadLibrary("PrivateCrypto");
    System.loadLibrary("myLibrary");

}

我使用Kit-kat进行Ubuntu系统测试。 请帮我解决这个错误。

2 个答案:

答案 0 :(得分:2)

您下载了一些错误的OpenSSL for Android版本,该版本未正确构建(类似于this one。Android does not support versioning in SONAMEs

您可以找到更好的预建版OpenSSL,但不建议这样做。为了将这些库委托给您的秘密通信,您应该更好地确保自己从受信任的(official)源构建它,并且它不会将您的私人信息泄漏给某个流氓第三方。

作为最低限度修复,您可以try to use patchelf 实用程序来修复库中的SONAME。

答案 1 :(得分:1)

我通过在android.mk文件中进行一些小改动来解决这个问题

我删除了.so文件并放置了.a文件。

我的android.mk现在看起来像这样

  LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := ssl_static
LOCAL_SRC_FILES := precompiled/libssl.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := crypto_static
LOCAL_SRC_FILES :=precompiled/libcrypto.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := myLibrary

LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := ssl_static crypto_static
include $(BUILD_SHARED_LIBRARY)

got this idea from here

link