Is there someone who had experience with this error?
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file \"/data/app/org.swig
What helped me was to register the source directory for jni files in the build.gradle file. Add this to your gradle file:
android {
sourceSets {
main {
jniLibs.srcDir '[YOUR_JNI_DIR]' // i.e. 'libs'
}
}
}
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 Samsung S6 and S6 Edge.
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 my app works on S6 and S6 Edge. I mean it works on every devices which has new 64-bit processors.
Update :
As of Dec/2019 armabi and mips are deprecated. Supported ABIs are [arm64-v8a, armeabi-v7a, x86, x86_64]
So, your code should be like this
defaultConfig {
...
ndk {
abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
}
}
Please note that there's a naming convention. Your lib needs to be called libexample.so .
LoadLibrary("example") will look for libexample.so.
The .so library needs to be inside the apk under the lib folder (since you are developing for Android, it needs to be under the lib/armeabi and lib/armeabi-v7a folders - why both folders ? some versions of Android look under lib/armeabi and some look under lib/armeabi-v7a ... se what works for you ).
Other things to look for :
make sure you compile for the correct architecture (if you compile for armeabi v5 it won't work on armeabiv7 or armeabiv7s ).
make sure your exported prototypes are used in the correct class (check the hello jni example. Your exposed functions need to look something like Java_mypackagename_myjavabridgeclass_myfunction).
For example the function Java_com_example_sample_hello will translate in the java class com.example.sample , function hello.
This could be device related issue.
I was getting this error in MI devices only, code was working with all other devices.
This might help:
defaultConfig{
...
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
}
}
}
Simple Solution with Pics
Step1: Add following code in build.gradle file under defaultConfig
ndk {
abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
}
Example:[![enter image description here][1]][1]
Steo 2: Add following code in gradle.properties file
android.useDeprecatedNdk=true
Example: [![enter image description here][2]][2]
Step 3: Sync Gradle and Run the Project.
@Ambilpur
[1]: https://i.stack.imgur.com/IPw4y.png
[2]: https://i.stack.imgur.com/ByMoh.png
For me the problem was in NDK_ROOT not being set.
Check your console if:
NDK_ROOT = None [!] NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties
Check if you have set: