[android] java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader

Is there someone who had experience with this error?

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.swig.simple-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "liborg.swig.simple.example.so"

Error occurs when I load library by this way.

static {
    System.loadLibrary("example");
}

I'm sure 'example' class is exist in the current folder.

This question is related to android c++ swig android-library

The answer is


Yet another crash cause and possible solution is described in this article: https://medium.com/keepsafe-engineering/the-perils-of-loading-native-libraries-on-android-befa49dce2db

Briefly:
in build.gradle

dependencies {
    implementation 'com.getkeepsafe.relinker:relinker:1.2.3'
}

in code

static {
    try {
        System.loadLibrary("<your_libs_name>");
    } catch (UnsatisfiedLinkError e) {
        ReLinker.loadLibrary(context, "<your_libs_name>");
    }
}

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'
        }
    }
}

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"
                    }
                }
    }

I use Android Studio 3.0 and encounter this problem. And I'm sure app's build.gradle is OK.

Go to Run -> Edit Configurations -> Profiling, and disable "Enable advanced profiling".

This works for me. Reference answer


If you are using Android studio, just edit the gradle.properties in the root folder and add android.useDeprecatedNdk=true. Then edit the build.gradle file in your app's folder, set abiFilters as below:

android {
....
defaultConfig {
    ....
    ndk {
        abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
    }
}
}

In my case After running the ndk-build in the jni folder the shared library was created under the libs folder but the path specified in build.gradle

sourceSets.main {
        jni.srcDirs = []
        jniLibs.srcDir 'src/main/jniLibs'
    }

so I need to move the created shared library to jnilibs folder and it worked!


What worked for me was to place the jniLibs folder under the "main" folder, just besides the "java" and "res" folders, for example project -> app -> src -> main -> jniLibs

I had all the libraries with the correct names and each one placed on their respective architecture subfolder, but I still had the same exception; even tried a lot of other SO answers like the accepted answer here, compiling a JAR with the .so libs, other placing of the jniLibs folder, etc.

For this project, I had to use Gradle 2.2 and Android Plugin 1.1.0 on Android Studio 1.5.1


This helped me. Sharing it for someone who might come up with same issue.

android {
    ....
    defaultConfig {
        ....
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }
    }
}

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"
        }

    }

This is worked for me

If your having .so file in armeabi then mention inside ndk that folder alone.

defaultConfig {
        applicationId "com.xxx.yyy"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        renderscriptTargetApi 26
        renderscriptSupportModeEnabled true
        ndk {
            abiFilters "armeabi"
        }
    }

and then use this

android.useDeprecatedNdk=true;

in gradle.properties file


Some old gradle tools cannot copy .so files into build folder by somehow, manually copying these files into build folder as below can solve the problem:

build/intermediates/rs/{build config}/{support architecture}/

build config: beta/production/sit/uat

support architecture: armeabi/armeabi-v7a/mips/x86


-if gradle.properties not available then first add that file and add android.useDeprecatedNdk=true

-use this code in build.gradle

defaultConfig {
    applicationId 'com.example.application'
    minSdkVersion 16
    targetSdkVersion 21
    versionCode 11
    versionName "1.1"
    ndk {
        abiFilters "armeabi"
    }
}

`


Ensure you have included the different abiFilters, this enables Gradle know what ABI libraries to package into your apk.

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

If you storing your jni libs in a different directory, or also using externally linked jni libs, Include them on the different source sets of the app.

sourceSets { 
  main { 
    jni.srcDirs = ['src/main/jniLibs'] 
    jniLibs.srcDir 'src/main/jniLibs' 
    } 
}

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

If you use module with c++ code and have the same issue you could try

Build -> Refresh Linked C++ Projects

Also, you should open some file from this module and do

Build -> Make module "YourNativeLibModuleName"


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:

  • NDK_ROOT and SDK_ROOT in C/C++->Build->Environment
  • Android->NDK
  • Android->SDK

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to swig

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader

Examples related to android-library

Cannot resolve symbol AppCompatActivity - Support v7 libraries aren't recognized? java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader Adding external library in Android studio Import Android volley to Android Studio Android - java.lang.SecurityException: Permission Denial: starting Intent How do I add a library project to Android Studio? Adding a library/JAR to an Eclipse Android project