Android学习问题记录之java.lang.UnsatisfiedLinkError

1.问题描述

Android Studio引入第三方类库时,出现错误java.lang.UnsatisfiedLinkError:

11-09 14:58:05.500 13280-13280/cn.com.altotech.easeimtest E/AndroidRuntime: FATAL EXCEPTION: main
Process: cn.com.altotech.easeimtest, PID: 13280
java.lang.UnsatisfiedLinkError: 
Couldn't load hyphenate from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/cn.com.altotech.easeimtest-1.apk"],nativeLibraryDirectories=[/data/app-lib/cn.com.altotech.easeimtest-1, /system/lib]]]: findLibrary returned null
    at java.lang.Runtime.loadLibrary(Runtime.java:358)
    at java.lang.System.loadLibrary(System.java:526)
    at com.hyphenate.chat.EMClient.loadLibrary(Unknown Source)
    at com.hyphenate.chat.EMClient.getInstance(Unknown Source)
    at cn.com.altotech.easeimtest.MainActivity.onCreate(MainActivity.java:29)
    at android.app.Activity.performCreate(Activity.java:5231)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
    at android.app.ActivityThread.access$800(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5045)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)

2.问题原因

原因是Android Studio加载so类库失败,导致so文件没有编译到apk里面去,所以导致UnsatisfiedLinkError错误。

3.解决办法

在build.gradle设置so文件路径,设置方法:打开app/build.gradle,在android的标签下加入如下代码:

sourceSets 
{
    main 
    {
        // 设置Jni so文件路径
        jniLibs.srcDirs = ['libs']
    }
}

转载于:https://www.cnblogs.com/iZander/p/6047154.html

你可能感兴趣的:(Android学习问题记录之java.lang.UnsatisfiedLinkError)