[SOLVED] UnsatisfiedLinkError Problem on Some Android Devices

I am currently working on an android application which streams radio. I use native decoder library which is called aacdecoder. Everything was fine till app gets crash error on some android devices. It was really annoying. Because app was perfectly plays radio streams almost all devices but not on devices with new 64bit processor.

Crash report says that

Fatal Exception: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.radyoland.android-1/base.apk”],nativeLibraryDirectories=[/data/app/com.radyoland.android-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn’t find “libaacdecoder.so”
 at java.lang.Runtime.loadLibrary(Runtime.java:366)
 at java.lang.System.loadLibrary(System.java:988)
 at com.spoledge.aacdecoder.Decoder.loadLibrary(Decoder.java:187)

As you see that crash is saying that it could not load native library. But why?

First of all I checked my structure, If native library .so files located correctly.

Seems everything was okay except this crazy error. Then after some research, I find out that some of android devices has 64-bit processors. This devices generates and check arm64 folder to load native library. That was the problem. Because my project does not have arm64 folder. Here is the solution;

defaultConfig {
    ...

    ndk {
        abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
    }

}

You need to add this filters(abiFilters) to your app module’s build.gradle files. So when your device try to run your app, it will check gradle file and understands that it should not generate any folder and use existing native library resources. Boom. Almost solved. But still there is one more thing.

android.useDeprecatedNdk=true

Add this line to your gradle.properties to use deprecated Ndk.

Finally the app works. I mean It works on every devices which has new 64-bit processors.I hope you guys find this blogpost get the issue solved.

Leave a Reply

Your email address will not be published. Required fields are marked *