7

I'm building an android application. Encode and decode using Opus codec. I'm using native code from here http://www.opus-codec.org/ and the wrapper from here https://github.com/jitsi/libjitsi/tree/master/src/native/opus . In Android 4.0+, I created .so file and run, everything is OK. but in Android 5.0, It crash when I call native method. Here is the detail of crash:

 java.lang.UnsatisfiedLinkError: No implementation found for long my.package.name.codec.Opus.encoder_create(int, int) (tried Java_my_package_name_codec_Opus_encoder_1create and Java_my_package_name_codec_Opus_encoder_1create__II)

I also search a lot but can't find the root cause and nobody has a same problem with me. below is my mk file, I think it useful.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

MY_MODULE_DIR       := opus

LOCAL_MODULE        := $(MY_MODULE_DIR)
LOCAL_SRC_FILES     := $(wildcard ( libopus/src/*.c \
    libopus/celt/*.c \
    libopus/celt/arm/*.c \
    libopus/silk/*.c \
    libopus/silk/arm/*.c \
    libopus/include/*.c \
    libopus/silk/fixed/*.c \
    my_package_name_codec_Opus.c ))

LOCAL_C_INCLUDES    := \
    libopus/src \
    libopus/include \
    libopus/silk \
    libopus/silk/fixed \
    libopus/silk/arm \
    libopus/celt \
    libopus/celt/arm \
    libopus \

LOCAL_CFLAGS        := -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
LOCAL_CFLAGS    += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -O3 -fno-math-errno
LOCAL_CPPFLAGS      := -DBSD=1 
LOCAL_CPPFLAGS          += -ffast-math -O3 -funroll-loops

include $(BUILD_SHARED_LIBRARY)

PS: if you need more files, please let me know.

4

1 回答 1

8

在自己花费大量时间调试相同的问题、启用 checkjni、运行 javah 以确保我的标头与我的 java 代码匹配、使用 PIE 编译之后 - 我最终发现了问题。

Android 5.0 增加了对作品的支持。这意味着系统已经带有一个 libopus.so 文件。当您运行 loadlibrary 时 - 加载的不是您的编译版本,而是与 Android 捆绑在一起的 libopus.so。

只需将您的库名称更改为 libmyopus.so,这应该可以解决您的问题。MY_MODULE_DIR := myopus 当然也更新您的 System.loadlibrary 调用。

于 2015-01-03T22:26:17.557 回答