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