尝试将FFmpeg与NDK一起使用时出现UnsatisfiedLinkError

时间:2014-04-05 00:06:08

标签: java android android-ndk ffmpeg java-native-interface

我编译FFmpeg for android没有任何问题,但当我尝试在设备上运行应用程序时,会得到不满意的linkerror。

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libavcodec
LOCAL_SRC_FILES := lib/ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/lib/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavfilter
LOCAL_SRC_FILES := lib/ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/lib/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavformat
LOCAL_SRC_FILES := lib/ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/lib/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavutil
LOCAL_SRC_FILES := lib/ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/lib/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libswscale
LOCAL_SRC_FILES := lib/ffmpeg/$(TARGET_ARCH_ABI)/lib/$(LOCAL_MODULE).so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/lib/ffmpeg/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := native
LOCAL_SRC_FILES := native.c
LOCAL_SHARED_LIBRARIES := libavcodec libavfilter libavutil libswscale libavformat
LOCAL_LDLIBS := -L$(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-arm/usr/lib \
                -L$(LOCAL_PATH)/lib/ffmpeg/$(TARGET_ARCH_ABI)/lib \
                -llog \
                -lz \
                -ldl \
                -lgcc \
        -landroid \
        -ljnigraphics

include $(BUILD_SHARED_LIBRARY)

native.c(空c文件.rly !!)

MainActivity.java

//Trivial blahblah code
...

static {                                                                                
     System.loadLibrary("avformat");                                                     
     System.loadLibrary("avcodec");
     System.loadLibrary("avutil");
     System.loadLibrary("avfilter");                                                     
     System.loadLibrary("swscale");
     System.loadLibrary("native");
}

...

我尝试为ffmpeg注释掉System.loadLibrary(),但没有运气。

我注意到当我使用loadLibrary()从Android.mk中删除-lavformat -lavcodec ...时,它会使用空的native.c进行编译。但是,当我尝试在native.c中编译一些有用的代码时,这会导致编译错误,如:error:undefined reference to'avformat_open_input' - 当我添加-lavformat时会得到解决...

我在stackoverflow中看到了类似的帖子并试了一堆,但没有运气。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

您可以将logcat从本机库的加载发布到完整的UnsatisfiedLinkError消息吗?

如果使用共享C ++库(如gnustl_shared)编译了ffmpeg,则需要对其进行集成(通过在 Application.mk 中设置APP_STL := gnustl_shared)并加载它在ffmpeg libs之前。