Java.lang.UnsatisfiedLinkError when used with android 5.0

I am creating an Android application. Encode and decode with Opus codec. I use the native code 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 a .so file and ran it, everything is fine. but in Android 5.0, it crashes when I call my own method. Here is the detail of the accident:

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 am also looking for a lot, but I can not find the root cause, and I do not have the same problem. below is my mk file, I think it is 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.

+6
source share
1 answer

After spending a ridiculous time debugging the same problem, turning on checkjni, running javah to make sure my headers match my java code, compiling with PIE - I eventually found the problem.

Android 5.0 has added support for opus. This means that the system is already shipped with the libopus.so file. When you run loadlibrary, this is not your compiled version downloaded, but rather libopus.so, which was bundled with Android.

Just change your library name to libmyopus.so and this should solve your problem. MY_MODULE_DIR: = myopus and, of course, update your System.loadlibrary call.

+7
source

Source: https://habr.com/ru/post/979266/


All Articles