我使用Guardian项目中的scripts与openssl支持交叉编译FFmpeg,但是每当执行以下操作时我的代码都会崩溃:
System.loadLibrary("crypto"); // loads OK
System.loadLibrary("ssl"); // loads OK
System.loadLibrary("avformat"); // crashes
错误:
dlopen("/data/data/wseemann.media.demo/lib/libavformat.so") failed: dlopen failed: cannot locate symbol "SSL_library_init" referenced by "libavformat.so"...
我使用工具链构建libavformat,然后使用以下Android.mk文件运行ndk-build来创建.so文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libswscale
LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libavcodec
LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libavformat
LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libavutil
LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_PATH:= $(call my-dir)
似乎libavformat在加载时需要libcrypto和libssl,但它无法找到它们或者没有加载它们。有谁知道如何解决这个问题?
答案 0 :(得分:1)
问题是libssl.so
中通常有/system/lib
。加载程序System.loadLibrary()更喜欢到app lib目录(/data/data/your.package.name/lib
)的路径,这可能会引起混淆。最简单的解决方法是使用System.load("/data/data/your.package.name/lib/libssl.so")代替(correct ways也可以获取路径)。
另一种解决方法可能是将您准备的libssl.so
重命名为libavssl.so
,然后致电System.loadLibrary("avssl")
。请注意可能,您需要重新编译libavformat
,以便查找libavssl.so
。