FATAL EXCEPTION: main java.lang.UnsatisfiedLinkError in Android Studio library

27,505

Solution 1

It looks like it's trying to load a native library, and there isn't support in Android Gradle for native code yet. You should double-check the docs for your library to confirm; I tried to look it up but it looks like it's a commercial library without publicly accessible docs.

Solution 2

You could just put the .so files into jniLibs folder in src/main. This was introduced in AS 0.7.2 1

As a sample, see this from @CommonsWare, or see this page for official samples (scroll to the bottom of page)

Solution 3

Here is my last hack when i was integrating with the same library for finger print device while trying to import .so files into Android Studio 1.5 Error occurred in this line

sgfplib=new JSGFPLib((UsbManager)getSystemService(Context.USB_SERVICE));

Solution was to create a folder with the name armeabi-v7a in src/main/jniLibs so the hierarchy should be as the attached screen shot.

enter image description here

Hope this can help :) with the latest Android Studio 1.5

Solution 4

There is a way .. but it is a simple hack. U can bind armeabi folder inside which there is XXXX.so files.

these are the native codes and as @Scott Barta said there isn't support in Android Gradle for native code.

So lets wrap it like our normal jar files.. Step 1: create a folder and name it 'lib' Step 2: took the armeabi>xxxx.so files inside the lib folder. Setp 3: now zip the lib file and name the zipped file as XXXXX.zip.

Now the project structure will be XXXX.zip-lib-armeabi-xxxx.so

Step 4: Copy the zip file to Libs folder of android studio. Step 5: Rename the xxxx.zip to xxxx.jar Step 6: paste the code below in the dependency of gradle.

dependencies { compile fileTree(dir: 'libs', include: '*.jar') }

Now Sync gradle and then run.

Note: This armeabi will work only if the cpu of emulator is armeabi. For intel x86 you may need to create 'x86' folder inside zip and paste corresponding .so file in that folder.

This worked for me. try it :)

Happy coding..

Share:
27,505
Ramprasad
Author by

Ramprasad

Android Developer - Develop Apps for Mobile,Tablet,Watch and Google Glass

Updated on February 03, 2020

Comments

  • Ramprasad
    Ramprasad over 4 years

    I added FDxSDKProAndroid.jar file in libs folder of my project in android studio. Also added dependency in build.gradle file.

    dependencies {
        compile 'com.android.support:support-v4:18.0.0'
        compile 'com.google.android.gms:play-services:4.0.30'
        compile files('libs/FDxSDKProAndroid.jar')
    }
    

    Project builds properly without any error but onRuntime I got following error,How to resolve this error?

    Error occured in following line,

    sgfplib=new JSGFPLib((UsbManager)getSystemService(Context.USB_SERVICE));
    

    Error:

    12-04 13:35:13.022  12345-12345/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
        java.lang.UnsatisfiedLinkError: Couldn't load jnisgfplib from loader dalvik.system.PathClassLoader[DexPathList[dexElements=[zip file "/data/app/com.mycompany.mytrack-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.mycompany.mytrack-1, /vendor/lib, /system/lib]]]: findLibrary returned null
                at java.lang.Runtime.loadLibrary(Runtime.java:359)
                at java.lang.System.loadLibrary(System.java:514)
                at SecuGen.FDxSDKPro.JSGFPLib.<clinit>(JSGFPLib.java:150)
                at com.mycompany.mytrack.FingerPrintActivity.onCreate(FingerPrintActivity.java:105)
                at android.app.Activity.performCreate(Activity.java:5122)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
                at android.app.ActivityThread.access$600(ActivityThread.java:156)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:153)
                at android.app.ActivityThread.main(ActivityThread.java:5297)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
                at dalvik.system.NativeStart.main(Native Method)
    12-04 13:35:13.033      511-529/? E/AppErrorDialog﹕ Failed to get ILowStorageHandle instance
    
  • Ramprasad
    Ramprasad over 10 years
    Yes Still no support for native library in Android gradle.Just I followed simple hack.It works great.groups.google.com/d/msg/adt-dev/nQobKd2Gl_8/Z5yWAvCh4h‌​4J
  • anon
    anon over 9 years
    This worked for me. I was having the same issue with the Twilio SDK.
  • Avinash R
    Avinash R over 9 years
    @Ramprasad, I don't think this may be the correct answer anymore.
  • Achin
    Achin over 7 years
    yes , this is only the working solution , Thanku so much
  • Mahesh Gawhane
    Mahesh Gawhane over 7 years
    @Mohamed i dont have jniLibs folder in my app. how to add it.
  • Mohamed
    Mohamed over 7 years
    @MaheshGawhane actually you have to create it yourself.
  • Ali Ahmed
    Ali Ahmed almost 4 years
    link to @CommonsWare answer is broken